First thing on the command line: CD ~
Main content: add, delete, change and check
Search: View a file or directory
View the absolute path of the current directory
- PWD (CD ~/desktop/ can change the current path to the desktop)
View the current directory
- ls
View the contents of a specified directory
- Ls path
Viewing file Contents
- Cat path (show all)
- Head path (to show the first ten lines, use [space +-n+ space + desired number of lines, such as -n 14] to see the desired number of lines)
- Tail path (to show the last ten lines, use [space +-n+ space + desired number of lines, such as -n 14] to see the desired number of lines)
- Less path (only part of the path is displayed, that is, split screen, press the arrow key to scroll, Q exit)
Add: Create a file
Create a file
- touch 1.txt
- Echo hi>1.txt
- Echo hi>>1.txt
- Echo -e “1\n2”>1.txt
Create multiple files
- touch 1.txt 2.txt
Create a file
- Mkdir a(create a folder in current directory)
- Mkdir -p a/b/c(create a/b/c folder in the current directory with -p as parameter)
Create multiple directories
- mkdir -p a/b/c a/d/c
Copy the file
- cp 1.txt 2.txt
Copy directory
- Cp -r a b (-r means recursive, must add -r to copy directory)
Delete: Deletes a file
- rm 1.txt
- rm -r a
- Rm -rf a(f stands for force, forcibly deleted)
Modify: Modify a file or directory
Modify or append file contents
- Echo hi>1.txt
- Echo hi>>1.txt
Empty file
- Echo “>1.txt (place empty string in 1.txt)
- Code 1.txt (select all delete code after opening the file)
Move files/directories
- Mv 1.txt a (put 1.txt into a folder)
- Mv a/1.txt. (Put 1. TXT in a into the current directory, which is abbreviated as.)
Renames files/directories
- Mv 1.txt 2.txt (rename 1.txt to 2.txt)
Change the last update time of a file
- Ls-1 View the update time of a file