Linux Basics 1
1. Directory pwd: displays the full directory name
Cd: enter the current user's home directory
Cd.. / (cd..): return to the directory one level above
Cd -: returns the last operation
Cd ~: home directory
Cd / tmp: switch to the specified directory (press the tab key once to automatically complete and print all relevant information twice)
Clear: # clear screen
two。 View file or folder ls # displays the file name and folder name under the current directory
Ls-a # View all files and folders, including hidden files, hidden files to. The beginning
Ls-l # to view the details of files and folders (including creation time, permissions, size, etc.), abbreviated as ll
Ll-d # View folders and folder information (including creation time, permissions, size, etc.), excluding names
Ll-h # view the information of files and folders, the difference from ll is that the file size is expressed in k
Du-sh # View file and folder sizes
Ll-t (- rt) # sort by the time the file was created (in reverse order)
Note: ll-h is ls-lh is the actual size of the file
Du-sh shows the block size occupied by the file; block defaults to 4k.
3. View the contents of the file cat file name # View the contents of the file (not suitable for reading large files)
More file name # View the contents of the file, display it as a page, and turn the page with the spacebar
Tail file name # directly view the contents at the end of the file
Tail-n file name # View the contents of the last n lines of the file
Tail-f file name # View the contents of the file
Tail-F file name # View the contents of the file
Note: F is to monitor all the time. After the file is moved, a new file with the same name will continue to check its contents.
4. Create directory (mkdir) mkdir filename # create directory (folder)
Mkdir filename1 filename2 # create two directories
Mkdir-p / XXX/xxx/:# creates a multi-level directory
5. Create a file (touch echo) touch file # create an empty file
Echo "123" > > aa.txt # append 123s when creating aa.txt, > to add after emptying
Vi xxx.sh # create a script file
6. Delete directory (rmdir) rmdir directory name # Delete a directory (empty directory)
7. Delete file (rm) rm file name # Delete a file
# rm abc
Rm: remove regular empty file `abc'? Y
Rm-r-recursive recursive deletion
Rm-f is forcibly deleted without prompt
Rm-rf force recursive deletion
Rm-rf * # Delete all the contents of the current folder (use with caution! )
8. Copy file (cp) cp copy copy
9. Move or rename a file (mv) mv move move
10. Overlay and append
>: overwrite the contents of the file >: append the contents of the file (added at the last) 11. Output and Import (echo) echo "123": print 123
Echo "123" > File name: overwrite the contents of the file to 123
Echo "123" > > File name: append 123 to the end of the file
twelve。 Help command (man help) man command: view the help information of the command (details), ctrl+z exit view
Command-help: view help information for a command
Edit mode and command mode of vivi
Edit mode: finish editing the text.
Command mode: realize the operation of the file.
Trailing mode: after entering command mode using esc, when saving the file or exiting, enter trailing mode first and use shift+:.
Vi filename: enter command mode, use "A", "a", "O", "o", "I", "I" keys, and switch to edit mode
A: add text at the end of the current cursor line
A: adds text after the character of the current cursor
I: insert text at the beginning of the current cursor
I: insert text before the character of the current cursor
O: inserts a line of space before the line of the current cursor
O: inserts a space after the line of the current cursor.
Operation in command mode
Gg: the cursor stops at the first line, the first character.
G: the cursor stops at the last line, the first character.
Dd: cut one line of the cursor
DG: delete the line of the cursor, that is, all the lines below
Ndd (number + dd): cut n lines below the cursor
D: cut from the location of the cursor to the end of the line
P: paste
Yy: copy a row
Nyy (number + yy): copy the n lines below the cursor
The shift+$: cursor moves to the last character of the line.
Operation in trailing mode
Wq: execute the save exit operation in command mode
W: perform save operation in command mode
Q: in command mode, execute the exit vi operation
Q! In command mode, perform a forced exit vi operation
Wqstores: force save + exit.