Linux cainiao records common Linux commands and miscellaneous for your reference.
- Some useful shortcut keys
<Ctrl + E> the cursor jumps to the end of the command.
<Ctrl + A> jump the cursor to the start of the command
<Ctrl + u> clear all content from the front of the cursor to the beginning of the line [this can be used to delete the entire line of input commands]
<Ctrl + k> clear the content from the cursor to the end of the row
<Ctrl + Y> paste or restore the last deletion.
Z ---- indicates calling the gzip or gunzip command to compress or decompress the file;
X ---- indicates decompression package
F ---- specifies the file
V ---- indicates the compression or decompression process.
Frequently used:
① Package: Tar CVF **. tar file or directory
② Unpack: Tar xvf **. Tar
③ Package and compress: Tar czvf ** .tar.gz file or directory
④ Unpack and compress: Tar xzvf ** .tar.gz
⑤ List the package content:Tar tzvf ** .tar.gz
6. decompress the package to the specified directory:Tar xzvf ** .tar.gz-C/home/zhangy
Du [-options] [filename]
Du calculates the actual disk space occupied by the specified directory or file. If no directory or file name is specified, the current directory is counted.
- All files include hidden
-M The default output of the du system is kb, which is displayed in MB as the parameter-M.
-S Count the total size of all files in this directory
-H Display Unit: k \ m \ G
Run the following command to view the total directory or file size: Du-SH name
View all information of the current directory: Du-ah
View hard disk usage
-H outputs the disk capacity status of all installed file systems in a friendly format
This is generally used as follows: DF-H
Change the group to which the archive belongs
Chgrp [-R] group name file or directory
Change archive owner
Chown [-R] account name file or directory
Chown [-R] Account name: group name file or directory
Chmod: Change the right of an archive
Chmod [-R] 777/754 and other digital files or directories (Binary represents the read, write, and execute permissions from high to low)
Chmod [-R] [U/g/O/A] [+/-/=] [R/W/X] files or directories (add, subtract, or assign read, write, and execution permissions)
(In the preceding command, when-R is used to modify directory properties, the subdirectories are recursively executed)
1. Basic usage
Search for the error string in a file
$ Grep "error" log.txt
2. Ignore case-insensitive search (-I)
$ Grep-I "error" log.txt
3. Search all subdirectories (-R)
$ Grep-R "exception" log.txt
4. Full match search (-W)
If you search for Boo, the query results may include fooboo, boo123, booooom, and so on. You can use-W to limit full-word matching.
5. Search for the start character (^)
If you search for rows starting with an int, you can write: grep '^ int '***
Correspondingly, the search end character is $
In particular, you can use: grep '^ $' to find blank rows'
6. wildcard (*/.)
. Represents any character
* Represents any number of characters or 0 characters
$ Grep-W "boo"/path/to/File
I usually use grep-I-r-W "XXX"./(recursively searches for all characters of XXX in the current directory and ignores case-insensitive matching)
Supplement:
Grep queries the rows containing the specified string.
The-V parameter indicates the inverse, that is, the row without the specified string;
-The I parameter is case-insensitive.
This command is usually used together with the MPs queue, for example:
History | grep ls Search for lines containing "ls" in History commands
History | grep-V ls Search for lines without "ls" in History commands
Grep-C "STR" filename count the number of matched strings
Search for files, commonly used:
Find [path]-name filename
For example:
Find/home-name "librt *" (wildcards can be added)
The search condition can be a combination of multiple logical operator links. For example, the following command concatenates three conditions with-O (indicating 'or') to find all the conditions in the current directory. CPP file ,. H files and files with a 755 ownership limit.
Find./-name '*. cpp'-o-name '*. H'-o-Perm 755
See: http://blog.csdn.net/whyhonest/article/details/8070673
The sort command is used to sort data based on different data types. Its syntax and common parameter format are: Sort [-bcfmnscn] [source file] [-O output file].
Note: Sort can sort the content of text files by unit of action. Sort compares each row of a file as a unit. The comparison principle is to compare the lines from the first character to the back, compare them by ASCII code values, and output them in ascending order.
$ Sort 1.txt Output the sorting result to the screen
$ Sort 1.txt | uniqRemove duplicate rows
$ Sort 1.txt> 2.txtRelocate the sorting resultResult File
Uniq can check repeated columns in text files.
Parameters:
-C or -- count displays the number of repeated occurrences of the row next to each column.
-D or -- repeated only displays repeated columns.
Soft link: ln-s target file link file
NL [-bnw] filename
When displayed, the output line number
-B A: indicates that the row number is allowed to be listed no matter whether it is empty or not.
-B T: if there are empty rows, do not list the row numbers for empty rows. [Default]
-N ln: the row number is displayed on the leftmost side of the screen.
-N rn: the row number is displayed on the rightmost side of the field without 0. [same as default]
-N rz: the row number is displayed on the rightmost side of the field and 0 is added.
-W: number of digits occupied by the row number field
WC [-options] [filename]
Statistics
-C: number of characters displayed
-L number of lines displayed
-L display the length of the longest row in a file
-W: Number of words displayed
Supplement:
The WC command can list the number of lines, characters, and characters in a file. It is usually used together with the pipeline command, for example:
Cat example. c | WC
E: unable to locate package mysql-Server
If this error occurs, run sudo apt-Get update to update the source and try again.
You can use alias to alias a command, and unalias to cancel the alias. For example:
Alias View defined aliases
Alias his = 'History' His is equivalent to the history command, shorter
Alias Rm = 'rm-I'
The-I parameter is added to the RM command and a confirmation prompt is displayed.
Unalias his
Cancel alias his
Http://blog.csdn.net/lewsn2008/article/details/9110577
Many may mistakenly think that/usr is the abbreviation of/user. In fact, USR is the abbreviation of UNIX software resource, that is, the directory where "UNIX operating system software resource" is stored, instead of user data! The system administrator installs the software downloaded by himself on the local machine (not the distribution modemtion provider). We recommend that you install the software in this project to facilitate management.
- Ls-LRT // sort by time in reverse order
- Uname-A // view the Linux kernel and other information
- History-C // clear the history command
- Tree // display directory tree
- Umount-N/mnt/hda2 // force uninstall
- Free-M // memory displayed in MB
- WC-l // number of statistics rows, WC-W statistical words
- BC // go to mathematical computing
- Command getconf long_bit // return 32 or 64 to check whether the system is a 32-bit or 64-bit version