Today to learn two Linux commands: Tail and grep.
The tail command writes the file to the standard output from the specified point. Using the-f option of the tail command makes it easy to refer to the changing log file, which is often used to track system log files, and tail-f filename will display the tail contents of the filename on the screen, and constantly refresh, Make you see the latest file content.
Tail Command parameters:
-F Loop Read
-Q does not display processing information
-V Display detailed processing information
Number of-c< > bytes displayed
-n< number of rows > show rows
–pid=pid is shared with-F, which ends after the process id,pid dead.
-q,–quiet,–silent never outputs the header of a filename
-s,–sleep-interval=s is shared with-F, which means sleeping s seconds at each repeated interval
Tail command trace displays log files:
[Root@localhost ~]# tail-f Test.log
This allows you to see the latest Test.log output in the window, automatically refreshing to display the latest content.
Another Linux command grep is described below.
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print matching rows. The grep full name is global Regular Expression Print, which represents the global regular expression version, and its use permissions are all users.
grep command Main parameters
-C: Only the count of matching rows is output.
-I: case-insensitive (applies to given only).
-H: Do not display file names when querying multiple files.
-L: Only file names that contain matching characters are output when querying multiple files.
-N: Displays matching rows and line numbers.
-S: Do not display error messages that do not exist or do not match text.
-V: Displays all rows that do not contain matching text.
Pattern Regular Expression main parameter:
\: Ignores the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: Matches the end line of a regular expression.
\<: Starts with the line that matches the regular expression.
\>: To the end of the line that matches the regular expression.
[]: A single character, such as [a], that is, a meets the requirements.
[–]: range, such as [A-z], that is, a, B, c all the time until Z meets the requirements.
。 : all the individual characters.
*: There are characters, the length can be 0.
The grep command uses a simple instance
$ grep ' test ' d*
Displays the rows that contain test in all files that start with D.
$ grep ' test ' AA bb cc
Displays the row that matches test in the aa,bb,cc file.
$ grep ' [a-z]\{5\} ' AA
Displays all the lines that contain at least 5 consecutive lowercase characters for each string.
$ grep ' West.*\1′aa
If West is matched, es is stored in memory and labeled 1, then searches for any character (. *), followed by another ES (\1), and the line is displayed. If you use Egrep or GREP-E, you do not use the "\" to escape, directly written ' W (es) t.*\1′ on it.
The grep command uses a complex instance
Suppose you are searching for files with string ' magic ' in the '/usr/src/linux/doc ' directory:
$ grep magic/usr/src/linux/doc/*
sysrq.txt:* How do I enable The Magic SysRq key?
sysrq.txt:* I Use the Magic sysrq key? The
where file ' Sysrp.txt ' contains this string, discusses the functionality of the SYSRQ.
By default, ' grep ' searches only the current directory. If there are many subdirectories under this directory, ' grep ' will be listed as follows:
Grep:sound:Is A directory
This may make the ' grep ' output difficult to read. Here are two solutions:
explicitly requires searching subdirectories: Grep-r
or ignoring subdirectories: grep-d Skip
If you have a lot of output, you can go through the pipe to read on ' less ':
$ grep magic/usr/src/l inux/documentation/* | Less
This allows you to read more easily.