Table of contents
3. Interception of file content
Fourth, the command of statistical file content
1. Command to view files
1.1 vi command
vi file name //Open the file in the vi editor and view it
1.2 cat command
cat file name // view the contents of the file
cat -n filename //display file content with line number
eg:
1.3 head command
head file name //View the content at the beginning of the file and display the first 10 lines by default
head -n 2 filename //Display the content of the first 2 lines at the beginning of the file
head -20 filename
1.4 tail command
tail file name //View the content at the end of the file by default displaying the last 10 lines
tail -3 file name //Display the content of the last three lines of the article
tail -n 20 filename //Display the first 20 lines at the end of the file
tail -f file name //Dynamic view the new content of the file
1.5 more command
more file name //Scrolling display file information is displayed in percentage
enter key scroll down q exit
1.6 less command
less file name //Scroll to display file information Press the up and down keys to scroll
1.7 View binary files
od -c binary filename
Second, find the file command
2.1 grep command
grep option "word to look for" filename //find the word to look for in the file
Commonly used options for the gerp command
-n display line number
-i ignore case
-w Absolute search, no prefix or suffix
-v reverse selection
-R recursive search, will find the contents of the files in the subdirectory
The grep command can combine wildcards to search for files
eg: Enter grep "main" -nR ./* in the terminal //Indicates to search for lines containing "main" in all files under the current directory and its subdirectories.
Specific usage reference of wildcards: wildcards and regular expressions
2.2 find command
find path-name file name //Find the specified file under the specified path and its subdirectories
find path-type bspflsc //Find files according to type (bspflsc)
b block device file s socket file p pipe file
f Ordinary file l (lowercase L) Linked file
c character device file
Notice:
The find command can also operate on a directory or file. It is a file-by-file search, so we need to pay attention to the use of wildcards. eg:
When we use the find command and use wildcards to match files ending with .c, we are not looking for all the .c files in the current path and its subdirectories, but will match *.c first in the current path if there are many in the current directory a .c file,
The command will become find ./ -name ac bc and an error of too many parameters will be reported.
3. Interception of file content
cut -d specifies the delimiter -f specifies the field
When cut processes content, it is processed in units of lines. If there is no specified separator in a line, it will not be processed.
eg:
grep -n "Qingqing Prairie" ./hello.c | cut -d : -f 7
grep -n "Qingqing Prairie" ./hello.c means to find a line containing Qingqing Prairie in the hello.c file
| is a pipe character, the function is to use the result of the previous command as the parameter of the following command
cut -d : -f 7 means to find the content of the seventh field with: as the separator
Fourth, the command of statistical file content
wc file name statistics file information
Options: -l (lowercase L) only counts the number of lines line
-w only counts the number of words word
-c only counts the number of characters char
eg: