Introduction of the command

The tac command is used to join and print the contents of a file line by line in reverse order.

As with the cat command, each file is concatenated to standard output, but in reverse order, printed line by line, with the last line printed first. This is useful for checking log files in chronological order (for example), where the last line of the file contains the most recent information.

Syntax format

tac [OPTION] ... [FILE] ...
Copy the code

Option to show

-b # concatenate separator before instead of after -r # Treat separator as base regular expression (BRE) -s # Use STRING as separator instead of default newline --help # display help information and exit --version # display version information and exitCopy the code

Application, for example,

Output a file in reverse, starting from the last line to the first line (compared to cat)

[root@centos7 ~]# tac test.txt This is also also a test line This is also a test line This is also a test line This is a  test line This is a test line This is a test line [root@centos7 ~]# cat test.txt This is a test line This is a test line This is a test line This is also a test line This is also a test line This is also also a test lineCopy the code

Learn one Linux command per day (98) : crontab

Learn a Linux command every day (99) : nohup

Learn one Linux command every day (100) : iotop