One, grep command(1) command format grep [option] pattern [file] (2) Common parameter parameter description-C calculation find ' search string ' (that is, pattern) number of times-I ignore case difference, so the case is treated as the same-N output line number-V reverse selection, print unmatched row-R recursive search --color=auto will find the keyword part plus color display (3) Common example one: the/etc/passwd file appears in the root of the line out, the keyword part of the color display, you can use the following command: grep "root"/etc/passwd-- color=autocat/etc/passwd | grep "Root"--color=auto example two: Remove the/etc/passwd file from the root and Nologin row, you can use the following command: Grep-v "root"/etc/passwd | Grep-v "Nologin" example three: in the current directory recursive search file contains main () files, often used to find some of the functions in which source code files, you can use the following command: Grep-r "Main ()". 2.3 Regular Expressions and grep The command regular expression metacharacters consist of the following characters: ^ $. [ ] { } - ? * + ( ) | \ (1) Example of a common example: use the Linux system to find a dictionary of five-letter words, the third letter is J, the last Letter is R,/usr/share/dict directory to store the dictionary file, you can use the following command: grep ' ^. j.r$ ' Linux.words Example two: Verify the fixed phone, print the eligible phone, fixed phone format is basically with 0 area code + Connector "-" + phone number, there may be extension number, area code has 3, 4 bit, phone number has 7 and 8 bits, you can use the following command: grep "^0[0-9]{2,3}-[0-9]{7,8} (-[0-9]{3,4})? $" Telphone.txt Area code: Front one 0, followed by 2-3 digits: 0[0-9]{2,3} phone Number: 7-8 digits: [0-9]{7,8} Extension: generally 3-4 digits: [0-9]{3,4} Note that there is no matching output when executing the following command, because there is no add-e option, and that is because grep takes. As a shell wildcard, not a meta-character of a regular expression.
two, tail command The tail command is primarily used to display the content at the end of a specified file. Common view log files. (1) command format tail [options] [file] (2) Common parameter parameter description-F loop Read-Q does not display processing information-v display verbose processing information-c< bytes > displayed bytes-n< rows > Display rows (3) Example of a common example: display Shiyanlou.log the last 5 lines of the file, you can use the following command: Tail-n 5 Shiyanlou.log Example two: Display Shiyanlou.log file The last 5 lines of content, when the Shiyanlou.log file has new content added, automatically update the display Shown You can use the following command: Tail-n 5-f shiyanlou.logping www.shiyanlou.com >> shiyanlou.log This command is to ping the remote host and append the information to the Shyanlou.log text Components. & 's role is to put this command in the background to execute, so that the Shiyanlou.log file will always have a content increase. Note that the ping command under Linux will continue to execute and must be stopped manually. When a ping is performed under Windows, a certain request is sent and stopped automatically. With the-f option of the tail command, you can instantly output the content appended to the file change, and tail-f filename will display the most up-to-date contents of the filename on the screen, and not only refresh, so you see the latest file content. Also, by the way, how to view the tasks running in the background and how to stop the task. The jobs command can view tasks that are running in the background. The kill command kills a task, but uses the ID of the task. The ID of the task can be viewed through the PS command the ability to get the 2.5 cat Command Cat command is to output a file or standard input combination to the standard output. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols. The cat command is an abbreviation for concatenate. (1) command format cat [options] [file] (2) Common parameters-A--show-all equivalent to-vet-b--number-nonblank to non-null output line number-e equivalent to-ve-e--show-ends show $-n at the end of each line Er for all lines of output numbered, starting from 1 for all output lines number-s--squeeze-blank has two consecutive lines toBlank line on the substitution of a row of blank lines-T and-VT equivalent-T--show-tabs to display the tab character as ^i-u (ignored)-V--show-nonprinting use ^ and M-reference, in addition to LFD and TAB (3) Common example one: Shiyanlou.log file content plus line number after input zhou.log This file, you can use the following command: Cat-n shiyanlou.log > Zhou.log Example Two: Add the Shiyanlou.log file content after the line number input Zho U.log this file, multiple lines of empty lines for the output, you can use the following command: Cat-ns shiyanlou.log > Zhou.log Example Three: The Zhou.log file content inverted display, you can use the following command: TAC Zhou.log Description: TAC is to write the cat back, so it functions like cat instead, the cat is continuously displayed on the screen from the first line to the last row, while the TAC is displayed on the screen in reverse from the last line to the first line. To
Third, find command (i)The main function of the Find command is to traverse down the file hierarchy, match the qualifying files, and perform the appropriate actions. (1) command format find [options] [Search path] [expression] The default path is the current directory, and the default expression is-print. An expression may consist of the following components: Operators, options, test expressions, and actions. (2) Common parameters-print the Find command outputs a matching file to the standard output-exec the Find command executes the shell command given to the matching file-name the file name to find the files-type find a file of a certain type-prune use this option to make The find command does not look in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command-user find the file according to the owner of the file-group find the file according to the group to which the file belongs-mtime-n +n to find the document by the time the file was changed ,-n means that the file change time is now less than n days, +n indicates that the file change time is now greater than n days, and the Find command has-atime and-ctime options Other command command options and expressions can be found. (3) Example of a common example: Print the list of files in the current directory, you can use the following command: Find. -print Example Two: Print all file names ending in. txt in the current directory, you can use the following command (show only part): Find. The-name "*.txt"-print-iname option works the same as the-name option, except that-iname ignores the case of letters. Example three: Print all the file names in the current directory ending in. txt or. pdf, using the following command (show only part): Find. \ (-name "*.pdf"-or-name "*.txt" \) example four: Print all file names not ending in. txt in the current directory, you can use the following command: Find. ! -name "*.txt"
Find Command (ii)The following describes how to find matching files based on file type, permissions, owner, and operator. Depending on the file type to find the file, using the-type option, common find file types are shown in the following table. To find files based on file permissions, use the-perm option. The owner uses the-user option. In addition, the Find command can create more complex logical relationships with logical operators, such as example three in the Find command (a), which uses the-or operator. The logical operators of the Find command are shown in the following table. (1) Example of a common example: print all the symbols in the current directory with the end of the. txt link, you can use the following command: Find. -type l-name "*.txt"-print Example II: Print all PHP files with 777 permissions in the current directory (PHP files on the Web server generally need to execute permissions), you can use the following command: Find. -type f-name "*.php"-perm 777 cases Three: print all files owned by the root user in the current directory, you can use the following command: Find. -type F-user Root Example four: print all files in the current directory that are not 777 and 664, you can use the following command: Find. -type f \ (!-perm 777-and!-perm 644 \)
Find Command (iii)The following describes how to use the-exec option of the Find command to implement a specified action command on a found file (1) Example one: Find all the PHP files in the current directory and display their details, you can use the following command: Find. -name "*.php"-exec ls-l {} \;-exec is the action that the Find command performs on the found file, which is the command for the found file, and the command above is ls-l {}. Here is a description of {} and \;,{} is actually a placeholder, during the execution of the Find command will be replaced by the currently found file, equivalent to "ls-l found files." and \; is the-exec command end tag, because the command-exec the following commands must end, but, in the shell has special meaning, must be escaped, so write \; Example two: In the experimental building environment has a lot of their own written C language code files, now want to download all C language code files, if one of the download is very troublesome, we can first find all the C language code files, and then write the contents of these files to a file, download the file, You can use the following command: Find. -name "*.C"-exec cat {} \; > ALL.C Example three: By default,-exec can only use a single command after, if you want multiple commands, you can write multiple commands to the script file, and then use the script in-exec, you can use the following command: Find. -name "*.c"-exec./command.sh {} \;
Xshell Common Commands