Head Command Chinese Introduction:
Usage: head [options] ... [File] ...
Displays the first 10 lines of each specified file to standard output.
if more than one file is specified, the filename is given as the file header before each segment of output.
If you do not specify a file, or if the file is "-", the data is read from standard input.
parameters that must be used for long options are also required for short options.
-C,--bytes=[-]k displays the first K-byte content of each file, and
if the "-" parameter is attached, displays all remaining content except the last K-byte data for each file-
N,--lines=[-]k Displays the contents of the first k lines of each file, and
if the "-" argument is attached, all remaining contents are displayed except for the last K line of each file-
Q,--quiet,--silent does not display the file header-V with the given file name.
--verbose always displays header--help with the given file
name Display this Help information and exit
--version display version information and exit
K with multiplication:
b 1000, KB, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, for T, P, E, Z, Y are equally applicable.
Tail command detailed
Usage: tail [options] ...
[File] ...
Displays the last 10 lines of each specified file to standard output.
If more than one file is specified, the program adds the corresponding file name as the header at the beginning of each segment of output.
If you do not specify a file or file as "-", the data is read from standard input.
Parameters that must be used for long options are also required for short options.
-C,--bytes=k output the last K bytes, in addition, using the-C +k output from the K-byte of each file-F,--follow[={name|descriptor}] The data appended after the file changes. -F,--follow equals--follow=descriptor-f that is--follow=name--retry-n,--lines=k outputs the last K line, instead of the last 10 lines, using-n +k from each file's K-byte output-
-max-unchanged-stats=n uses--follow=name to reopen a file that has not changed size after N (default 5) iterations to see if it is disconnected or renamed (this is the usual case of circular log files).
This option is rarely used because of the inotify. --pid=pid is used in conjunction with-F, when the PID corresponding process dies and terminates-Q,--quiet,--silent does not output the header of the filename--retry even if the target file is inaccessible and still tries to open; in the parameter--follow=nam
E is often used at the same time.
-S,--sleep-interval=n with-f, sleep for approximately N seconds (default 1.0) between iterations.
With INotify and--pid=p, the check process P at least once every N seconds. -V,--verbose always output headers giving file names--help Display this Help information and exit--version display version information and exit if the first character of the number of bytes or lines K Is "+", the output starts from the file K entryMesh, otherwise output file the last K items.
K can use one of several units: B 512,kb 1000,k 1024,mb 1000*1000,m 1024*1024, GB 1000*1000*1000,g 1024*1024*1024, and T,p,e,z,y. If you want to trace a valid name for a file instead of describing it (such as circular logs), the default program action is not what you would like. You can use the--follow=name option on this occasion, which causes tail to periodically trace open a file of the given name to confirm that it was deleted or recreated by some other program.
Head: Print the first 10 lines of the file (default)
Tail: Print the following 10 lines of the file (default)
If you are a typical developer or deployer, do you feel like you're starting to get kind. Most of the commands we normally use.
$tail-F Catalina.out
$head
Instance:
1. Print Head.txt, tail.txt the first 10 lines
$head Head.txt Tail.txt
Copy Code code as follows:
==> Head.txt <==
Head.txt Content
==> Tail.txt <==
Tail.txt Content
2. Print 1K content
$head –c1k Head.txt
3. Print the first 5 lines of content
$head-n5 Head.txt
4. Print out all lines except the last 5 lines
$head-N-5 Head.txt
Here-5 means negative 5
Interpreting--help
Copy Code code as follows:
Usage: head [options] ... [File] ...
Displays the first 10 lines of each specified file to standard output.
If more than one file is specified, the filename is given as the file header before each segment of output.
If you do not specify a file, or if the file is "-", the data is read from standard input.
Parameters that must be used for long options are also required for short options.
-C,--bytes=[-]k displays the first K-byte content of each file;
If the "-" parameter is attached, in addition to the last K-byte data for each file
Show all remaining content
-N,--lines=[-]k displays the contents of the first K rows of each file;
If the "-" parameter is attached, then the last K line of each file is displayed except
All remaining content
-Q,--quiet,--silent does not display header with the given file name
-V,--verbose always displays header with the given file name
--HELP displays this help information and exits
--version display version information and exit
K can be followed with multiplication:
B, KB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, for T, P, E, Z, Y also apply.
Interpretation:
The only note here is that if you do not specify a file, or if the file is "-", the data is read from standard input.
$tail
Instance:
1. Print the last 10 lines of a file
$tail Tail.txt
2. Trace log, print the last few lines of the file, and keep reading append data
Tail-f Tail.txt
Interpreting--help
Usage: tail [options] ...
[File] ...
Displays the last 10 lines of each specified file to standard output.
If more than one file is specified, the program adds the corresponding file name as the header at the beginning of each segment of output.
If you do not specify a file or file as "-", the data is read from standard input.
Parameters that must be used for long options are also required for short options.
-C,--bytes=k output the last K bytes, in addition, using the-C +k output from the K-byte of each file-F,--follow[={name|descriptor}] The data appended after the file changes. -F,--follow=name--retry-n--lines=k outputs the last K line instead of the last 10 lines; span style= "color: #000000" >-n +k from each file The K-byte output--max-unchanged-stats=n uses--follow=name to reopen a file that has not changed size after N (default 5) iterations to see if it is disconnected or renamed (this is the usual case of circular log files).
This option is rarely used because of the inotify. --pid=pid is used together with-F to terminate-Q--quiet when the PID corresponding process dies,--silent does not output the header of the filename--retry even if the destination file is not
Access is still trying to open, and it is often useful to use it at the same time as parameter--follow=name. -S--sleep-interval=n with-f, sleep for approximately N seconds (default 1.0) between iterations.
With INotify and--pid=p, the check process P at least once every N seconds. -V--verbose always output headers giving file names--help Display this Help information and exit--version display version letter and exit if the number of bytes or lines K is the firstThe character is "+", the output starts from the file K item, otherwise the output file is the last K item. K can use one of several units: B 512,kb 1000,k 1024,mb 1000*1000,m 1024*1024, GB 1000*1000*1000,g 1024*1024*1024, and T,p,e,z,y.
Interpretation:
1. Distinguishing between-F and-F
Borrow Online An example:
window 1 Input
$while ["true"]; Do Date >>test.log; Sleep 1; Done
#每隔一秒传入一个日期到test. Log
Window 2 input
$tail-F Test.log
Window 3 Input
$RM Test.log
Window 2 stops printing, and Test.log has been regenerated
If you use-f, a new test.log is regenerated, but automatically re-read the
Closure
Tail and head are two very common commands that are proficient at viewing the contents of a file. The two are simple and very similar, so write them together.