Commands that must be mastered in Linux
-------------------- Grep ---------------------- working method: search for a string template in one or more files. If the template contains spaces, all strings after the template is referenced must be considered as file names, common parameters for the content of the original file are not affected:-a: searches for data in the form of a text file.-c: calculates the number of times the string template is found, the row content that matches the string template will not be output. Only the number of outputs-I: case-insensitive-n: when the output is performed, the row number will be output together-v: reverse selection, output the line without a string template -- color = auto: add the color of the searched string template section (usually default, no need to set) for exact search: add "\>" to the string template of www.2cto.com to make the string search more precise. For example, to search for "546", if "5462" and "5468" still exist ", then execute the command grep "546" to find both "5462" and "5468", but we only want "546". At this time, grep can be like this. "546 \> ".
----------------- Sed ------------------------- working method: replaces, deletes, adds, and selects each row of data in the unit of action, and does not support operations on a single row. Common parameters include-n: Quiet Mode, this parameter is used when you want to print the selected row to ensure that the specified row is not output repeatedly. If you do not add this parameter, generally, the next line is output twice in each row.-f: Write the sed action directly into a file. When-f filename is added, the sed action in filename can be executed, note: single quotation marks or double quotation marks are not allowed in filename. If the action is '2a hello', only 2a Hello should be entered in filename.-r is not required for anything: this allows sed operations to support extended regular expressions (sed is the basic Regular Expression by default)-I: directly modify the content of the file to be read and will not be output on the screen (Dangerous !!! Although it seems that sed can do some vim operations)
----------------- Awk ---------------------------- working method: Compared with sed, awk processes each field in a row, and each of its actions is included in, similarly, all actions must be placed in a pair of single quotes. In this case, the single quotes cannot appear in the action and can only be replaced by double quotes, its default field separator is space or tabulation key. Note that it is compared with grep and sed !!! Common functions of www.2cto.com: NF: Total number of fields owned by each row. print NR: the row number currently processed, and print FS: The current separator, the default value is space or tabulation key. The setting method is "BEGIN {FS =": "}". In this way, fields can be separated by colons, which are divided into $1, $2, $3 ......, awk supports conditional judgment in the/etc/passwd file.
----------------- Sort ---------------------- working method: sort and output the entire file data according to the selected sorting method, which can be sorted by letters, numbers, and within a certain range. Common parameters can also be output in reverse order: -f: Ignore case sensitivity (the same as the-I Parameter Function of grep, why is the same function? The parameters should be different)-B: Ignore the space character at the beginning of each line, B can be recorded as blank, and-B will delete blank-M: sort by month name. This parameter can be used to sort the output by time-n: sort by numbers (by default, the text type), n can be recorded as number-r: reverse Order and output, and r can be recorded as reverse-u: uniq, output a row of repeated rows with the-t: delimiter (the default is the tab key). Modify the-t': 'method to separate the rows with colons, it is useful in/etc/passwd. It is similar to the FS setting of awk-k: Which interval is used for sorting, usually combined with-t, when the content to be sorted is separated by the tab key, it is not mentioned. If you want to separate/etc/passwd with a colon, you need to use-t to modify the separator, then-k is added with the Field identifier to be used as the sorting standard.
----------------- Wc ----------------------- method of work: Count the word count, number of lines, and number of characters in the entire file. Of course, you can also use grep or sed to calculate the word count of a Specific Row and other common parameters: -l: only lists the number of lines, line-w: only lists the number of words (number of words), word-m: only lists the number of characters (whether to use-c, it corresponds to wc and characterize ...) If you only execute wc without adding any parameters, all information will be listed, in sequence: number of lines, number of words, number of characters
---------------- Find ----------------------- working method: directly search for files that meet the conditions on the entire disk. If the disk is too large, it will take a lot of time. There is also a command to find files: whereis, it searches for files in the database provided by the system, which is fast, but the system database is not updated in a timely manner. Therefore, to find the latest file, you must first run updatedb, otherwise, the file will not be found (but it may take a long time to update the database ...) Common parameters: "www.2cto.com-atime: query by file read time-mtime: query by file content modification time-ctime: based on the File Permission and attribute whitelist modification time, search for the above three parameters as the time parameter, followed by a number, such as-atime n: the time from the nth day before the nth day to the nth day of the nth day-atime-n: files that have been read within n days (including n days), from now to all times before n days-atime + n: Before n days (not including n days) after reading the file, there is another time parameter after the remaining time in the preceding two periods:-newer file: file is an existing file, as the name suggests, search for a file that is newer than file. "" file-gid:-uid n: file with user ID n "-gid n: file with user ID n"-user name: file with user account name-group name: file with user account name-nouser: Owner not Then, you can find some abnormal files in/etc/passwd-nogroup: files that do not exist in the user group. "" parameters related to file permissions and names:-name filename: file-size [+-] SIZE: Search for files larger (+) or smaller (-) than the SIZE, in the unit of c (bytes), k (1024 bytes) -type TYPE: Search for TYPE-type files. The TYPE indicates the first character of the permission. Common types include d,-, l... -perm [+-] mode: You can use the permission to search. mode indicates that the permission must be exactly the same. + mode indicates that the permission contains any (three groups, -mode indicates that all permissions of the mode must be included (it seems that it is not easy to remember ..) 』 "Extension parameter:-exec command: exec is followed by a command. This command can be used to process the find result. It looks a bit like a pipeline command, however, the command format followed by it is relatively fixed. If we find a file named file and want to use exec to browse the file content, we must write the following command: [html] $ find-name file-exec cat {}\;{} indicates the searched content, \ is used to eliminate; special meaning in the command, it indicates that exec is executed until; end-print: the default operation, no need to add... 』 "Www.2cto.com, etc. find also has a special function, that is, searching for files by inode number. This function can solve the problem of deleting a file with spaces in the file name, such as the Hello World file name, if rm is used, it will mistakenly identify the file as two files and keep reporting errors. In this case, you need to find the inode Number of the file and delete it using the extension parameter of find, the command is as follows: [html] $ ls-I | grep 'Hello world'. If inode is found to be 142542, run the following command: [html] $ find-inum 142542-exec rm {}\; files with spaces will be deleted. "Www.2cto.com ---------------------- tar ------------------------- working method: compress files or directories, view the compressed Package content, and decompress one or all files in the compressed package. This can be understood in comparison with winRAR. This is just one of the most commonly used compression commands. Generally, it is best to name the files compressed with this command * .tar.bz2, which is different from the common parameters of the compressed package produced by other compression commands:-c: create a compressed file-t: view the file name in the compressed file-x: Decompress the file, and use-C to decompress the file in a specific directory-j: compress/decompress the file through bzip2, it is best to name it * .tar.bz2-z: compress/decompress through gzip. It is best to name it * .tar.gz-v: show the compressed file name-f filename: filename is the file to be processed (this parameter must be added to each tar command !!!) -C direction: As mentioned earlier, extract-p in a specific ction: allow the backup data to contain the root directory (in lower case)-P: Retain file permissions and attributes (in upper case) note: tar has three functions: decompression, compression, and viewing of compressed files. These functions cannot be performed simultaneously, that is to say, different-c,-t, and-x appear in the same command parameter. (You can use this DELETE command to delete the compressed exercise package and decompressed Directory: rm-r filename, of course, you can also delete the directory. It may be difficult to use rmdir when the extracted file contains a directory, because there should be something in the directory)
-------------- Chmod -------------------------- working method: Modify the file or directory permissions (which is extremely important in Linux !!) Common parameters:-R: progressive modification. When you want to modify the permissions of all directories or files under a directory, this parameter is very useful (this parameter also has similar functions in chown and chgrp, and chmod and these two are very important in the system security www.2cto.com): (1) use rwx to directly modify: "u = rwx, g = rx, o = rx" or "a + x "....... (2) Use numbers to modify: "777" or "644", etc.
--------------- Netstat ------------------ working method: used for network monitoring, the output network and the system's own process two common parameters:-a: all meaning, that is to say, all the connection, listener, and socket data are listed.-t: lists tcp network data packets.-u: Lists udp network data packets.-n: use the port number to replace the service name of the process.-l: list the services currently being monitored by the network.-p: list the process PID of the network service.
-------------- Ln -------------- working method: establish a connection with an existing file or directory, which is divided into two types: soft connection and hard connection. soft connection is similar to the shortcut in Windows, and only saves the point of one source file, the disk space is small. The hard connection generates a new file name through inode connection of the file system. No new file is generated. The two files are synchronized, And the permissions and attributes are identical. Common parameters:-s: Create a soft connection (hard connection by default)-f: if the target file exists, delete the target file and create it again.
---------------- Kill -------------- working method: kill the background process, run the jobs command first, and kill the process according to the number shown in the first column, for example, kill-9% 2, and the second process is forcibly terminated. Common parameters: www.2cto.com-l: letter l, display available signals, and the following numerical parameters-2: equivalent to [ctrl + c]-9: force delete a job immediately-15: terminate a job as a normal program, it is a normal termination, different from-9
---------------- Ps ----------------- working method: query the running processes in the system, more comprehensive common query than the jobs command: ps-l: view the bash process related to yourself ps aux: view All programs running on the system
Author fengxiaoke_fxk