Linux tac command: show file contents from the last line
Linux tac command Function Description
Using the tac command you can display the contents of the file from the last line, and you can see that tac is the reverse display of cat.
Linux tac command Syntax
tac [Option] [File]
The meaning of each option in the command is shown in the table:
Option | Description |
---|---|
-b | Add separator flags before lines instead of at the end of lines |
-r | Parse the separator flag as if it were a regular expression |
-s |
Use the specified string instead of a newline as a separator |
Linux tac command Demo
Display the contents of the /root/pu file starting from the last line
[root@rhel ~]# cat /root/pu
Hello Linux
Hello Red Hat
// First, use the cat command to view the contents of the /root/pu file
[root@rhel ~]# tac /root/pu
Hello Red Hat
Hello Linux
Display the contents of the /root/pu file using the character s instead of a newline as a separator
[root@rhel ~]# tac -s R /root/pu
ed Hat
Hello Linux