1. Access the directory

  • CD + space + file name
$ cd c/user/file        # indicates to enter the file folder
Copy the code

2. Display the current directory

  • pwd
$ cd c/user/file/pwd     # indicates the path to display file
Copy the code

3. Create a folder

  • Mkdir + space + file name
$ mkdir file        # creates file in the current path
Copy the code
  • Mkdir -p + space + directory path
$ mkdir -p file/file2/file3    # indicates that the created file3 is in file/file2
Copy the code

4. View the path

  • Ls Displays files or directories
$ file>file2>file3$ ls        # displays a file3 file or directory
Copy the code
  • ls -aList all files and directories under current directory, including hidden A (all)
$ file>file2>file3$ ls -a      # displays all files and directories under file3
Copy the code
  • Ls -l Lists file details
$ file>file2>file3$ ls -l    # displays the details of the file under file3
Copy the code
  • Ls-al lists all documents and details
$ file>file2>file3$ ls -al     # displays all files and details under file file3
Copy the code

5. Create a file

  • Echo Content > File nameWrite to a file
$ echo file>1.txt     # indicates that the contents of the 1.txt file are "file".
Copy the code
  • Echo content >! The file nameForce redirection, new content overwrites old content (this command is not supported on Windows)
$ echoFile2 >! 1.txt# indicates that the existing contents of 1. TXT are overwritten as file2, and the original content file is lost
Copy the code
  • Echo Content >> File nameAdd at the end of the file content
$ echo file2>>1.txt       The 1.txt file contains file and file2
Copy the code

6. Creating a file (2)

  • Touch + space + file nameIndicates that a file named Filename is created
$ touch file.txt       # creates a text file named "file"
Copy the code
  • Touch + space + file nameIndicates to change the update time of the file name
$ touch file.txt       # indicates to change the update time of file file. TXT
Copy the code

7. Copy files

  • Cp + space + original path + space + destination pathCopy a file to a new folder.
$ cp c/file/1.txt  c/file2        # indicates to copy the 1. TXT file to c/file2
Copy the code
  • Cp -r + space + original path + destination pathCopy the entire directory to a new directory.
$ cp -r A B         # indicates to copy the entire A folder to B folder.
Copy the code

8. Move the file (cut)

  • Mv + space + original path + destination path
$ mv A B        # indicates to cut the entire folder A to folder B.
Copy the code

9. Delete files

  • Rm + space + file pathDeletes a file in a path
rm c/user/A        # delete c/user/A file
Copy the code
  • Rm -f + space + file pathForcibly delete
rm -f c/user/B       # deletes file B forcibly
Copy the code
  • Rm -r + space + file pathDelete a directory
$ rm -r c/user/A       C /user/A: all files in A are deleted
Copy the code
  • Rm -rf + Target pathForcibly deletes a directory
$ rm -rf c/user/AA      # indicates that the c/user/AA directory is forcibly deleted
Copy the code

Remember: never run rm -rf /

10. Common tips

  • CD – to go back to the previous directory (the up arrow on the keyboard) to use the previous command

  • !!!!! Indicates that the last command was used

  • Alt+. Indicates that the last argument is used

  • xxx; Yyy indicates that you can run two commands in one sentence (both yyy commands are executed regardless of whether the XXX command is executed).

  • XXX &&yyy indicates that two commands can be executed in one sentence (only the XXX command can be executed, yyy command can be executed).

11. How do I enter a command?

  • \\+Enter

12. How to teach yourself the command line

  • man ls
  • ls -help
  • ls -h
  • ExplainShell.com

References:

  • Linux tutorial
  • Common Linux Commands
  • Common Linux Commands
  • Linux common commands:

This article is formatted using MDNICE