Linux Foundation and common commands

1.Linux directory structure

  1. bin (usr / bin, user / local / bin) # store common commands, such as cp, cat, chown etc.
  2. sbin (usr / sbin, user / local / sbin) # highly privileged instruction, or the instruction super user can use high privilege
  3. The core of boot # boot files, including files and image files connected
  4. opt # install the software, to host additional software installation can be stored in the directory, file storage software
  5. usr / local # directory to another host installation software, usually installed via source code compilation mode program
  6. home # home directory, when you create a normal user, home directory next time create the corresponding file
  7. root # system administrator user's home directory
  8. dev # device management, including cpu, disk, etc.
  9. etc # store configuration files
  10. lib / lib64 # dynamic library, mostly .so file
  11. media # device, when inserted u disk, CD-ROM, will mount this directory
  12. mnt # mount, the external memory may be mounted to the directory
  13. proc # virtual directory, system memory mapping, access to the directory can obtain system information
  14. selinux # security subsystem, the control program can only access a specific file
  15. srv #service shorthand, storage of data to be extracted after the service starts
  16. sys # System Folder
  17. tmp # temporary folder
  18. var # variables, habitual frequently modified files in the directory, such as log information

2.vi/vim shortcuts

  1. yy # copy of the current line, the current line 5yy copy down the line 5, and paste [p]
  2. dd # delete the current line, 5dd delete the current line down 5 lines
  3. Under / Keyword # naming-line mode / Enter a keyword search, enter n Find Next
  4. : Set nu /: set nonu # command-line mode, set / cancel the line number, enter into force
  5. G / gg #G last line of the file is reached, gg the first line of the file is reached
  6. u # undo
  7. : Set nu -> line number -> shift + g # jump to a specified line

3. shutdown restart

  1. shutdown

    shutdown -h now # immediate shutdown
    shutdown -h off after 1 minute 1 #
    shutdown -r now # restart immediately

  2. halt # direct use, equivalent to the shutdown
  3. reboot # reboot
  4. sync # sync data memory to disk

    We should execute sync command before shutdown or restart, to avoid data loss

4. User Management

  1. Add user

    # useradd username Adds the specified user
    to specify their home directory useradd -d specify the directory username add username #

  2. Add / Change Password

    # passwd username to specify the user to add or change passwords

  3. delete users

    userdel username # delete users, but retained the home directory
    userdel -r username # delete users and their home directories

  4. Query User

    id user name # queries user information

  5. Switch User

    su - username # to switch users without a password when switching low-privileged high privilege, on the contrary need to
    use the exit named user can switch back to the original

  6. Increase the user group

    # groupadd group name to increase the user group

  7. Delete Group

    groupdel Delete Group # Group Name

  8. Specifies the user group increases

    When useradd -g group name user name # increase user specified group

  9. Modifying User Groups

    usermod -g group name user name # modify user belongs

  10. View the current user

    whoami #who am i, view the current user

5. Practical instructions

5.1. Specifies the run level

  1. init command

    the init [0123456]
    0 off #
    1 # single user, can be used to recover lost passwords
    2 # multiuser state, no network
    3 # multiuser state, there is a network
    4 Reserved #
    5 # graphical interface
    6 # reboot

Single-user mode, to retrieve the root password steps:
Shutdown - >> when startup, press enter key guide - e >> input, edit the boot - >> Kernel selection, input edit the kernel e
- Input >> (space +1 ), set to run level 1, press enter to complete the editing, go back one level - >> input b, open the boot
- after >> start in single user mode, that is, as root enter, enter the command passwd root, you can set a new password

5.2. Help command

  1. man command

    [Command or configuration file] man # get help

  2. help command

    # get help command shell built-in commands help information

5.3. File Directory command

  1. # pwd command displays the current working directory absolute path
  2. ls command

    ls [options] [directory or file]
    LS -a # show all files in the current directory and directory, including hidden
    ls -l # show all file information in list mode

  3. cd command

    cd [parameters] # switch to the specified directory
    cd ~ # to return to their home directory
    CD .. # back one level

  4. mkdir command

    directory mkdir [option] to create
    mkdir -p [multi-level directory] # create multi-level directory

  5. rmdir command

    rmdir [option] to delete empty directories

    rmdir to delete empty directories, if there are files in the directory can not be deleted, then you can use: rm -rf to remove the directory

  6. Named touch

    touch filename # create an empty file

  7. cp command

    cp [options] source dest # copy files to a specified directory
    cp -r source dest # recursive copy the entire folder to a specified directory, duplicate files will be prompted to overwrite the
    \ cp -r source dest # recursive copy the entire folder to a specified directory, duplicate files directly overwritten without prompt

  8. rm command

    rm [options] you want to delete a file or directory
    rm -r # recursively delete the entire folder
    rm -f # Forced deleted without prompt

  9. mv command

    mv oldFileName newFileName # Duplicate file name
    mv source dest # moving files

  10. The cat command

    files cat [options] To view the
    display line numbers when viewing files File # cat -n

    cat instruction loaded directly entire file, so often used in conjunction with the pipe character: cat -n file | more
    contents of the documents referred to more displays, one can load a
  11. more instruction

    To see more documents #more instruction is based on the filters vi text editor, it is in full screen display content on page
    shortcuts:
    spacebar (space) # represents the page down
    Enter # on behalf of his party turned down
    q # representation immediately leave more, no longer display the file information
    Ctrl + F # to scroll down one screen
    Ctrl + B # return to the previous screen
    = # output current line number
    : f # output file name and current line number

  12. less instruction

    To view the file less # used split-screen view files, and more similar to, but stronger than more.
    When less load the file, not a disposable loading all the content, but to load files based on display requirements with high efficiency for large files.
    Spacebar (space) # represents the page down
    [pageDown] # turn down a
    [pageUp] # turn a page up
    / down search string string #, n: look down, N: look up
    ? Word # up string search string, n: look up, N: Find downwardly
    q # quit less

  13. And additional output redirection

    > # Output redirection, the original contents of the file will cover
    >> # append, not overwrite the original file, but append to the end of
    ls -l> a.txt # will list the contents written a.txt, covered with writing. If the file does not exist, create
    ls -l >> a.txt # append a list of written a.txt,
    CAT File 1> File 2 # 1 to cover the contents of the file to file 2
    echo the contents of the file # contents >> appended to the file

  14. echo command

    echo [options] [output content] # content output to the console
    echo $ PATH # Output Path environment variable

  15. head command

    head file # Display the beginning of the file, the default output 10 lines before
    5 line content file before head -n 5 # View file

  16. tail command

    File # tail end of the file is displayed, the default output 10 lines after
    the file tail -n 5 # 5 line displays the file
    tail -f file # real-time tracking of all document updates, commonly used in the work

  17. ln command

    ln -s [original file or directory] [soft connection name] # connection to the original file to create a soft, equivalent shortcut win the
    rm -rf soft delete soft connection # connection name, not connected with the soft-name /, otherwise Tip resource busy
    when we look for flexible connections cd, see the contents of the corresponding directory
    when we use the pwd view the catalog, either see a soft link directory, rather than pointing to a directory

  18. history command

    history # View the historic command
    history 10 # to view the most recently used 10 commands
    history! 5 # execute command number 5

5.4. Date of instruction

  1. date command

    date # display the current time
    date "+% Y-% m-% d% H:% M:% S" # display every minute when the date
    date -s "2019-07-15 11:11:11" # Set System time

  2. cal command

    cal # Display the current calendar
    cal 2020 # show calendar 2020

5.5. Search by category

  1. find command

    find instructions from the specified directory recursively traverse down its subdirectories, will meet the conditions or directory displayed on the terminal
    find / home -name * .txt # find the next home directory, all the txt file
    find / home -user nobody # Find home directory, the user name is nobody all files
    find / home -size + 20M # find home directory, all files larger than 20M of (+ n is greater than, less than -n, n-equal)

  2. locate command

    locate command can quickly locate the file path. locate command using the previously established system of all file names and paths in advance locate database to quickly locate the specified file. locate command without having to traverse the entire file system, fast. In order to ensure the accuracy of the results, the need to regularly update locate.
    locate hello.txt # search hello.txt, quickly locate
    due to the locate command based on a database query, so before the first run, you must use updatedb to create a database.

  3. grep named the pipe symbol |

    filtering lookup grep, pipe symbol "|" represents a named processing before transmitting the output to the back of the command processing.
    cat hello.txt | grep -ni yes # hello.txt find in the "yes" line, it is not case sensitive, and line numbers. -n display matching lines and line number, -i ignore the case of letters

5.6. Compression and decompression class

  1. gzip / gunzip command

    File # gzip compressed file, the compressed file is only .gz file. gzip compressed file will not retain the original file
    gunzip file .gz # unzip the file command

  2. zip / unzip command

    zip xxx.zip hello.txt # hello.txt compressed file xxx.zip
    ZIP xxx.zip -r / home / # compression / all files in the home directory of xxx.zip
    the unzip -d / opt / tmp / xxx.zip # extract the files to a specified folder, specify -d-extracting file storage directory

  3. tar command

    tar command is packed instruction, and finally packed file is the file .tar.gz
    tar [options] xxx.tar.gz packaged content
    -c # generate .tar package file
    -v # Display detailed information
    -f # specify the compression post filename
    -z # packing while compressing
    -x # unpack .tar file
    tar -zcvf a.tar.gz a.txt b.txt # will a.txt b.txt two files compressed into a.tar.gz
    tar - zcvf a.tar.gz / home / # compress the home directory a.tar.gz
    the tar -zxvf a.tar.gz # a.tar.gz to extract the current directory
    tar -zxvf a.tar.gz -C / opt / tmp / # a.tar.gz extract to the specified directory, the directory must exist

5.7 Group Management and Rights Management

  1. File / directory owner

    ls -ahl # view the owner of the file
    owner chown tom a.txt # modify a.txt for tom
    represent recursive chown -R tom / home / abc # -R, all subdirectories for files, and change the owner
    chgrp root a .txt # modify a.txt where the group root

  2. Change the user's group

    usermod -g group name user name # change the user's group
    usermod -d directory name, user name # change the initial user login directory

  3. authority management

    File permissions: the root -rwxrw the root-r--. 1 2 2 On Feb 09:39 ABC
    . 1) Bit 0 is determined file types: - a normal file, d directory, l soft connection, [C character device keyboard, mouse], b block hard disk file or
    2) 1-3 determines that the owner of file permissions have: r read, w write, x execution
    3) determining the file permissions of 4-6 where the group has
    4) bits 7-9 identify other users file permissions have
    5) 1 indicates that the file size, if it is a directory 4096
    6) the first root represents the file owner, the second root represents a file where the group
    7) 2, if a file is represented by the number of hard links If the directory is a subdirectory of the directory it indicates the number of
    time 8) represents the first time the operation
    9) abc indicates that the file name

    rwx for file: r for read can see the view, w represents can be modified, but it does not mean that you can delete files, delete files premise is to have write access to the directory where the file, x represents execute
    rwx for the directory: r for read, ls view, w represents modified, created in the directory + + delete rename files

    chmod u = rwx, g = x, o = x file directory name # change File directory permissions u: owner g: where the group o: other people a: Everyone
    chmod u + x # to the owner plus execute permissions
    chmod ax # remove execute permission to everyone
    chmod 744 file directory name is equivalent to # chmod u = rwx, g = r, o = r rules: r = 4, w = 2 , x = 1

6. Task Scheduler

Task scheduling: it refers to the system to perform a specific name or program at a time

    1. grammar

      crontab [options]
      -e # edit crontab task
      -l # query crontab task
      -r # delete all the current user's crontab tasks

    2. Specific usage

      */1 * * * * ls -l /etc >> /tmp/to.txt

    3. Placeholders Description

      * # A first hour of the first few minutes [0-59]
      in the second * # one day the first few hours [0-23]
      Third * # month in the first few days [1-31]
      * # in the fourth year of the first few months [1-12]
      fifth * # of the week and the week 7 [0-7,0] have expressed Sunday

    4. Special Symbol Description

      1) # represents any time *, a * represents the first example, every minute of every hour execution
      2), # represents discrete time, such as 8,10,12 * * * 0 represents the day 8:00, 10:00 perform
      3) - # as a continuous time, for example 05 * * indicates 1-3 per day from Monday to Wednesday 5:00 execution named
      4) * / n # representative of how often performed once, such as * / 10 * * * * on behalf of executed once every 10 minutes

Guess you like

Origin www.cnblogs.com/fdzang/p/11281086.html