Linux commonly used instructions: help and file directory instructions

1. Help instructions:

  • man [command or configuration file] (to get help information)

eg: man ls (check the help information of the ls command)

  • help [command] (get help information for shell built-in commands)

eg: help cd (see the help information of the cd command)

2. File directory instructions:

  • pwd (display the absolute path of the current working directory)
  • cd [parameter] (switch to the specified path, if there is no parameter, switch to your home directory)
    • cd .. (switch to the upper level of the current directory)
    • cd ~ (switch to your home directory)
  • ls (Display the files contained in the current working directory)
    • ls -a (show all files, including hidden files)
    • ls -l (display files in the form of a list, excluding hidden files)
    • ls -al (display all files in a list)
  • mkdir [directory to be created] (create a new directory)

eg: mkdir /home/dog/ (create a dog directory under the home directory)

  • mkdir -p [directory to be created] (create multi-level directory)

eg: mkdir -p /home/animal/cat/ (create /animal/cat/ two-level directory under the home directory)

  • rmdir [directory to be removed] (delete empty directory)

  • rm -rf [directory to be removed] (delete non-empty directories)

  • touch [File to be created] (Create an empty file, you can create multiple at the same time)

eg: touch ok1.txt ok2.txt (create two empty txt files at the same time)

  • cp (copy files to the specified directory)
    • cp -r (copy the entire folder recursively)
    • \cp (Forced to overwrite the file if it already exists)

eg: ① cp a.txt b/ (copy a.txt to the b directory)

② cp -rb/ c/ (copy folder b to folder c)

  •  rm (remove files or directories)

    • rm -r [file/directory to be removed] (recursively delete entire non-empty folders)

    • rm -f [File/Directory to be removed] (Forced deletion without prompt)

eg: ① rm a.txt (delete a.txt, you will be prompted to confirm the deletion)

② rm -rb/ (delete non-empty folder b)

③ rm -f c.txt (delete c.txt without prompting)

  • mv (Move or rename file/directory)

eg: ① mv ab (rename a to b)

② mv path_a path_b (move path_a to path_b)

That is: in the same directory, changing the file (folder) name is renaming, and different path is moving

  • cat (open the file as read-only)
    • cat -n [file_path] (open the file as read-only, display the line number)
    • cat -n file_path | more (open in read-only format, display line number, automatic page break)
  • more (similar to cat, open the file in full screen page)
    • more -[num] (display num rows at a time)
    • more +[num] (from line num)
    • Common operation commands:
      • Enter down n lines, need to be defined (more -n). The default is 1 line
      • Ctrl+F scroll down one screen
      • Space bar to scroll down one screen
      • Ctrl+B return to the previous screen
      • = Output the line number of the current line
      • :F output file name and line number of the current line
      • V invoke the vi editor
      • ! Command calls Shell, and execute the command
      • q Exit more

For more content, please see:  https://www.runoob.com/linux/linux-comm-more.html

  • less (open the file in split screen, similar to more, but with more powerful functions, support various display terminals that can be moved at will, and load content according to display needs)
  • > Instructions and >> Instructions:
    • > (Output redirection, will overwrite the original file content, if it does not exist, create it)
    • >> (Append, will not overwrite the original content, will be appended at the end)

eg: ① ls -l> a.txt (The files in the directory will be written into a.txt and overwrite the original content)

② ls -l >> b.txt (append the contents of the directory to the end of b.txt)

③ cat a.txt> b.txt (write the content in a.txt into b.txt and overwrite the original content), add the same

  • echo (output content to the console)

eg: echo $PATH (output PATH environment variable)

  • head [file] (display the beginning of the file, 10 lines are displayed by default)
    • head -n 5 [file] (display the first 5 lines of the file)
  • tail [file] (display the end of the file, the default display 10 lines), similar to head
    • tail -n 5 [file] (display the last 5 lines of the file)
    • tail -f [file] (track all updates of the file in real time)
  • ln (soft link, similar to creating shortcuts in windows)
    • ln -s [source file or directory] [link name] (create a soft link to the source file)

eg: ln -s /home linkToHome (create a soft link named linkToHome for the home directory in the current directory)

When using pwd to view the soft link path, the source file path is displayed

  • history (View historical commands that have been executed)

    • history 10 (display the most recently used 10 commands)

    • !3 (Execute the instruction number 3)

 

For more instruction details, please see: Novice Tutorial Linux Command Daquan

 

 

Guess you like

Origin blog.csdn.net/weixin_45191152/article/details/104158101