Linux View partial file content command head,tail,sed usage:
View file content in Linux the most commonly used cat,less,more and vim we are already familiar with, but these commands are to view the entire contents of the file, if you want to see part of the file can use Head,tail or sed, Here is a brief introduction to the usage of these commands:
1. To view the first few lines of a file, you can use the Head command, such as:
head-10/etc/passwd
2. To view the following lines of the file, you can use the tail command, such as:
tail-10/etc/passwd
Tail-f/var/log/messages
Parameter-F allows tail to keep reading the latest content, so there is real-time monitoring effect, when you are in the process of PPP dialing it is not very convenient!
3. To view the middle section of the file, you can use the SED command, such as:
Sed-n ' 5,10p '/etc/passwd
This allows you to view only lines 5th through 10th of the file.
Now the amount of data processed is very large, open the file for too long, do not open the file, directly with:
wc-l filename
Can count the number of lines of a file
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print matching lines. grep full name is the global Regular expression Print, which represents the version of the globally regular expressions, and its use rights are all users
2. Format
grep [Options]
3. Main parameters
[Options] Main parameters:
-C: Outputs only the count of matching rows.
-I: Case insensitive (only for single-character).
-H: The file name is not displayed when querying multiple files.
-L: Only file names that contain matching characters are output when querying multiple files.
-N: Displays matching lines and line numbers.
-S: does not display error messages that do not exist or have no matching text.
-V: Displays all lines that do not contain matching text.
Pattern Regular Expression Main parameters:
: Ignores the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: Matches the end line of the regular expression.
<: Starts from the line that matches the regular expression.
: End of line to match regular expression.
[]: A single character, such as [a], a meets the requirements.
[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.
。 : all the individual characters.
*: There are characters, the length can be 0.
4.grep command uses a simple instance
$ grep ' test ' d*
Displays all rows that contain test in a file that begins with D.
$ grep ' test ' AA bb cc
Displays the line that matches test in the aa,bb,cc file.
$ grep ' [a-z]{5} ' AA
Displays all rows that contain a string of at least 5 consecutive lowercase characters for each string.
$ grep ' W (es) T.*1′AA
Linux View File command