Linux command line – Basic Bash Shell command

Source: Internet
Author: User
Tags parent directory printable characters touch command file permissions


To start the shell:
    • /etc/passwd: contains a list of system user accounts and basic configuration information for each user
      • Each entry has seven fields and each field is separated by a colon
        • User name
        • User password
        • User's system UID
        • User's system GID
        • User's full name
        • Default home directory for users
        • User's default shell program


such as:Zmcheng:x:501:501: Zhangmingcheng:/home/zmcheng:/bin/bash


    • By default, the bash shell automatically processes commands in the. bashrc file under the user's home directory when it starts.
Shell prompt:
    • PS1: Controlling the format of the default command-line prompt
    • PS2: Controlling prompt formatting for subsequent command lines
    • Bash Shell prompt character descriptor
      • All prompt special characters start with a backslash (\)


PS: The character that is displayed for each line of the command.



Bash Brochure:


    • Open the Bash brochure: $man bash
    • Man plus any command that can show a detailed description of this command, such as man ls


Linux File system:


    • Linux stores files in a single directory structure, a directory called a virtual directory
      • The Linux virtual directory contains a base directory called the root directory
    • Root drive: The first hard drive installed on a Linux PC
      • The root drive contains the core of the virtual directory, where other directories are built
      • Some of the special directories that Linux creates with drives are called mount points
        • Mount point is the directory in the virtual directory that is used to allocate additional storage devices
        • The Linux virtual directory causes these directories and files to appear in these mount point directories, and then in fact they are stored in another drive
        • The file system is stored in the same drive, and the user files are stored in the other drive
    • CD command
      • If the user does not specify a target path, it will switch to your user home directory
      • Two ways of expressing the target path parameter
        • Absolute file path
        • Relative file path strength
          • .: Current Directory
          • .. : Parent Directory


List of files and directories:


  • ls command
    • Function: Displays the files and directories in the current directory
    • ls_colors environment variable supports color to differentiate different types of files
    • Single parameter
      • -F: Distinguishing between files and directories
        • After the directory name, add/
        • Add "*" to the back of the executable file
      • -A: Show hidden files with normal files and directories
      • -r: Lists the files in the directory contained in the current directory
      • -L: Output shown in long list format
        • The first line shows the total number of quick totals contained in the catalog
        • The following information is displayed on the second line and later in the file
          • File type: directory (d), file (-), character file (c) or block (b)
          • Permissions for files
          • Total number of hard links to files
          • User name of file owner
          • Group name of file genus
          • Size of File
          • When the file was modified
          • File or directory Name
    • Combination parameters: The double dash parameter must be entered separately, but the dash parameter can be combined input
      • -sail
        • -I: Lists the index nodes for each file
        • -S: List the file's fast size
        • Output information after the combination
          • Index node
          • File Fast Size
          • File permissions
          • Number of hard links pointing to a file
          • Document owner
          • Group of file genera
          • File size
          • File Last Modified Time
          • File real name
    • Filter Output List
      • ? : Represents a character
      • *: represents 0 or more characters


To create a file:


    • Touch command
      • Role:
        • Create the specified new file and use your user name as the file owner
          • The size of the file created by touch is 0
      • Modify the access time and modification time of an existing file without changing the contents of the file
        • Touch defaults to the current time, or by the-t parameter plus the specified time

$touch NewText

$touch- t 201605211607 oldtext


To copy a file:


    • CP command
      • Role: Copying Files and directories
        • When both source and destination are files: Copy the original file to a new file and name it as destination
          • If the destination file already exists, you are prompted to overwrite
      • Parameters
        • -F: Force overwrite the existing target file without prompting
        • -I: Prompt when overriding the target file
        • -P: Preserve file properties if possible
        • -r: Recursive copy File
        • -r: Recursive copy Directory
        • -U: Copy only if the source file is newer than the target file (equivalent to the update)


Link file:


    • A link is a placeholder in a directory that points to a file
    • Two categories of links
      • Symbolic links, i.e. soft links
        • Create command
          • Cp-s Source Destination
          • Ln-s Source Destination
        • The Linux system treats the soft link as a separate file with a different index node number than the source file, and the file becomes smaller
      • Hard Links
        • Create command
          • Cp-l Source Destination
          • ln source Destination
        • Creates a read file that contains the information and location of the source file, referring to the hard-link file equivalent to referencing the source file
          • Hard links and source files have the same index node number
        • A hard link can only be created between files on the same storage medium and cannot be created between files under different mount points, in which case a soft link can be used
    • Note: Multiple links can be created to point to the same file, but do not create multiple links to link files, otherwise confusing and easy to break


To rename a file:


    • MV Command
      • Renaming files in a Linux system is called Moving (move)
      • Moving a file can change the filename, but it retains the same index node number and timestamp
        • Moving a file with a soft link leads to trouble and causes the link to fail


deleting files


    • RM command
      • Removal of a Linux system called removal (remove)
      • Bash Shell does not have a recycle Bin or trash bin, so the deletion of files is permanently unrecoverable
      • The difference between deleting a soft and hard link file
        • Because the hard link and the source file have the same index node number, all even if the source file is deleted, the hard link will always maintain the index node number until the last hard link to delete his file
        • For soft links, the source files do not exist, they become invalid files


To create a directory:


    • mkdir command
      • Create a new directory and assign a new index node number


To delete a directory:


    • Two different ways
      • rmdir command
        • Only empty directories are deleted by default
      • RM command
        • Plus the parameter-R recursively deletes the files in the directory and finally deletes the directory itself
        • Plus the parameter-RF will be silently forced to delete the directory and its following files


To view file statistics:


    • Stat command
      • Provide all status information for a file on the system, including primary and secondary device numbers, etc.


To view file types:


    • File command
      • The file command divides the files into 3 classes
        • Text file: A file that contains printable characters
        • Executable files: Files that can be run on the system
        • Data files: Files that contain non-printable binary characters and that cannot be run on the system


To view the entire file:


    • Three implementation of the command
      • Cat command
        • Display all data in a text file
        • Parameters
          • -N: Add line numbers to all lines
          • -B: Add line numbers to lines with text only
          • -S: Compress multiple blank rows into a single blank line
          • -T: Hide tabs
      • More commands
        • The more command implements the text content, but stops after each page of data is displayed
        • Command options
          • H: Show Help Menu
      • Less command
        • Upgrade of the more command


To view some files:


    • Two implementation of the command
      • Tail command
        • Displays the end of the file, showing only 10 lines at the end of the file by default
        • Parameters
          • -F: Allows other processes to use the file to view the contents of the file, constantly displaying new content added to the file
      • Head command
        • Displays the contents of those lines at the beginning of the file, displaying the first 10 lines of the file by default, with the-F option not supported
        • A great tool for not knowing the contents of a file but for a rough idea


Linux command line – Basic Bash Shell command


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.