Linux basic commands and Linux basic commands
1. linux directory structure
Bin :( binaries) stores binary executable files
Sbin (super user binaries) stores binary executable files
Etc :( etce) stores system configuration files
Usr (unix shared resources) is used to store shared system resources.
Home: root directory for storing User Files
Root Super User directory
Dev (devices) Stores Device Files
Lib (library) stores the shared libraries and kernel modules required for running programs in the file system.
Install the temporary file system by the mnt (mount) System Administrator
Boot stores various files used for system boot.
Tmp (temporary) is used to store various temporary files
Var (variable) is used to store files that need to change data during runtime.
2. Switch directory command cd
Switch cd test to the test directory.
Cd... switch to the parent directory
Cd/switch to system and Directory
Cd ~ Switch to the user's home directory
Cd-switch to the previous directory
3. Directory operation commands (add, delete, modify, and query)
Add directory:
Mkdir directory name
Mkdir test is to generate a test directory under the current directory.
View the directory:
Ls
Ls: all directories and files under the current directory
Ls-a: You can see all the files and directories under this directory, including the hidden
Ls-l: Can be abbreviated to ll. You can see the details of the files in this directory.
Query Directory:
Find directory Parameters
Find/root-name '* test *': find the test-related directory file under/root.
Modify directory name:
Mv directory name new directory name
Mv oldTest newTest: change the name of the oldTest directory to newTest under the current directory.
Note: The music video syntax can not only rename directories, but also rename various files and compressed packages.
Move directory location (CUT ):
New location of the mv directory name directory
Mv newTest/usr: Cut the newTest file in the current directory to the usr directory.
Copy directory:
Cp-r directory name: Target Location of directory copy (r indicates recursive copy)
Cp-r/usr/newTest/test: copy the newTest file under usr to the test directory.
Note: The cp command can not only copy directories but also files. You do not need to write-r recursion to copy files and packages.
Delete directory:
Rm-rf directory
Rm-rf newTest/: Delete the newTest file in the current directory and all files in it, and do not need to ask
4. File Operation commands
File Creation
Touch file name (empty file)
Touch a.txt: Create an empty file named a.txt in the current directory.
File Viewing
Cat/more/less/tail files
Use cat to display only the content of the last screen
You can use more to display the percentage. Press enter to display the following line. spaces can be placed on the next page. q can be used to exit.
If you use less, you can use PgUp and PgDn on the keyboard to flip pages up and down, and check the q
You can use the tail-f file to dynamically monitor a file, just like the tomcat log file, which will change as the program runs.
Modify file content
Vim File
Vim startup command: vim filename open vim and create a file named filename
FILE command
Open a single file vim file
Open multiple files at the same time: vim file1, file2 ......
Open a new file in the vim window: open file
Open the file in a new window: split file
Switch to the next file: bn
Switch to the previous file: bp
View the list of currently opened files. The files being edited are included in []: args
Open a remote file, such as ftp or share folder.
: E ftp: // 192.168.10.76/abc.txt
: E \ qadrive \ test \ 1.txt
Vim Mode
Normal Mode (Press ESC + [key to enter). The file is displayed in the lower left corner or is empty.
INSERT mode (press the I key to enter) display in the lower left corner -- INSERT --
VISUAL mode: display in the lower left corner -- VISUAL --
Vim INSERT command
I: Insert before current position
I: insert at the beginning of the current row
A: insert after the current position
A: insert at the end of the current row
O: Insert after the current row
O: Insert before the current row
Vim SEARCH Command
/Text Search text, press the n key to find the next one, and press the N key to find the previous one
? Text Search text, reverse search, search for the next one by pressing the n key, and search for the previous one by pressing the N key
: Set ignorecase case-insensitive search
: Set noignorecase case-insensitive search
: Set hlsearch highlights the search results. All results are highlighted, instead of displaying only one match.
: Set nohlsearch disable highlighted search display
Search for a long word. If a word is long and difficult to type, move the cursor to the word and press * or #.
That is, you can search for the word, which is equivalent to/, while # The command is equivalent? Search
Vim replacement command
Ra replaces the current character with a. The current character is the character where the cursor is located.
S/old/new/Replace new with old to replace the first match of the current row
S/old/new/g Replace new with old, replace all matches of the current row
% S/old/new/Replace new with old, replace the first match of all rows
% S/old/new/g Replace new with old, replace all matching
Ddp exchange the row of the cursor and the next line
Vim mobile command
H shifts one character to the left
L shift one character to the right (w is generally used)
K move one character up
J. Move one character down
The preceding four commands can be used with numbers. For example, 20 J means 20 rows are moved down.
W moves a word forward. If it is at the end of the line, it is transferred to the beginning of the next line. This command block can replace the l command.
B. Move one word backward, and 3b move three words backward.
^ Move to the first non-blank character in the row
0 (number 0) Move to the first character of the row
$ Move to the end of a row
Gg move to File Header
G move to the end of the file
The f (find) command can also be used to move. fx finds the first x character after the cursor, and 3fd finds the Third d character.
F, same as f, Reverse Lookup
: 10 + press Enter: Jump to 10 rows, 10 Gb to 10 rows
Ctrl + e scroll down a row
Ctrl + y scroll up a row
Ctrl + d scroll down the half screen
Ctrl + u scroll up half screen
Ctrl + f scroll down one screen
Ctrl + B scroll up one screen
Vim undo and redo
U (Undo) Undo
U undo the whole row
Ctrl + r redo
Vim DELETE command
X Delete the current row
3x Delete the current cursor starting with three characters backward
X deletes the first character of the current character.
Dl deletes the current character
Dh deletes the current character
Dd deletes the current row
Dj deletes the previous row
Dk deletes the next row
10 days to delete the 10 rows starting with the current row
D. Delete the current character to the end of the line.
D $ Delete All characters after the current character (ROW)
Kdgg deletes all rows before the current row (excluding the current row)
JdG (jd + shift + g) deletes all rows after the current row
: 1, 10 days: delete 1-10 rows
: 11, $ d: delete 11 rows and all subsequent rows
: 1, $ d: delete all rows
J: merge two rows
Copy and paste vim
Yy copy the current row
Nyy copies n rows starting from the current row
P is pasted after the current cursor. If you have used the yy command to copy a row, paste it in the next row of the current row.
P paste before the current row
: 20th co 20 insert 1-10 rows to rows
: 1, $ co $ copy the entire file and add it to the end
Ddp exchange the current row and next row
Xp exchanges the current character with the next character
Vim cut command
In normal mode, press v (verbatim) or V (line-by-line) to enter the visual mode. Then, use the jklh command to move and select certain lines or characters. Then press d to cut.
Ndd cut the n rows after the current row, and the p command can be used to paste the cut content
: 1, 10 days Cut 1-10 lines, use the p command to paste the cut content
: 1, 10 m 20 move rows 1-10 to rows 20
Vim exit command
: Wq save and exit
: ZZ save and exit
: Q! Force exit and ignore all changes
: E! Discard all changes and open the original file
Vim window command
: Split or new opens a new window, And the cursor is on the top of the window
: Split file or: new file open the file in a new window
The split window is displayed horizontally. You can use vsplit to open the window vertically.
Ctrl + ww move to the next window
Ctrl + wj move to the window below
Ctrl + wk move to the window above
: You cannot use this command to close the last window to prevent accidental exit of vim.
: Q if it is the last closed window, it will exit vim
Run shell commands in vim.
:! Ls to list files in the current directory
:! Check the perl script syntax in perl-c script. pl. You do not need to exit vim.
:! Run the perl script in perl scrip. pl. You do not need to exit vim.
: Suspend or Ctrl + Z: suspend vim and return to shell. Press fg to return vim
Vim annotation command
In the perl program, # The Beginning of the behavior annotation, so to comment some rows, you only need to add at the beginning of the line #
3, 5 s/^/#/g comment line 3-5
3, 5 s/^/# // g uncomment 3-5 rows
1, $ s/^/#/g comment the entire document
: % S/^/#/g comment the entire document,
Vim Help commands
: Help or F1 displays the entire help
: Help xxx: Display xxx help
: Help 'number' the vim option is enclosed in single quotes
: Help <Esc> help for special keys <> Expand
: Help-tvim help-
Other non-edit commands of vim
. Repeat the previous command
: Set rtasks? Check whether rsequence is set. In. vimrc, you can use this command to view the options set by using the set command.
: Scriptnames: Check the location of the vim script file, such as The. vimrc file, syntax file, and plugin.
: Set list displays non-printable characters, such as tab, space, and end of line. If the tab cannot be displayed, use set
: Syntax list defined syntax items
: Syntax clear defined syntax rules
: Syntax case match is case sensitive. int and Int are considered different syntax elements.
: Syntax case ignore is case-insensitive. int and Int are treated as the same syntax elements and use the same color scheme.
5. Operation commands for file Suppression
In linux, the packaging file is generally ended with a slash (.), and the compressed command ends with a slash (.). In general, packaging and compression are performed together,
The suffix of the compressed file. tar.gz
Tar-zcvf package the compressed file name to package and compress the file. z indicates to use the gzip compression command to compress the file, c indicates the package file, v indicates the running process, and f indicates the specified file name.
Tar-zcvf xxx.tar.gz a.txt B .txt: Package a.txt and B .txt files under the current directory into xxx.tar.gz compressed files.
Decompress the compressed package: tar-xvf, x indicates decompression,
Tar-xvf xxx.tar.gz: Decompress the compressed file named xxx.tar.gz in the current directory.
Tar-xvf xxx.tar.gz-C/usr. C indicates the specified decompression location. This section indicates that the file is decompressed to the usr file.
6. Other commands
Pwd: displays the current location
The string to be searched by grep. The file to be searched.
Grep to test. conf: Search the line containing the string to in the test. conf file in the current directory.
| Use the output of the previous command as the input of this directory
Ps-ef | grep system: displays all processes in the current system that contain the system string.
Ps-ef: View processes running in the current system
Kill-9 the pid of the process to kill the process
7. Network Communication commands
View the NIC information of the current system: ifconfig
View the connection with a certain machine: ping
View the current system port usage: netstat-
8. linux permission commands
Each file/directory has permissions. You can use the ls-| command to view the permissions of files or directories under a directory.
R read permission
W write permission
X execution right
-No operation permission
The first symbol: d represents the directory,-represents the file, | represents the connection (can be considered as a shortcut in the window)
Chmod u = rwx, g = rw, o = r aaa.txt: indicates that the owner has all permissions to modify the aaa.txt file under the current directory. The group in which the owner belongs has the read and write permissions. Other users are read-only.