The tail command in Linux is used to display the last few lines of a text file. By default, it displays the last 10 lines of a file, but you can specify the number of lines you want to display using the `-n` option. Here are some examples:
1. Display the last 10 lines of a file (default behavior):
tail filename.txt
2. Display a specific number of lines from the end of a file (e.g., last 20 lines):
tail filename.txt
2. Display a specific number of lines from the end of a file (e.g., last 20 lines):
tail -n 20 filename.txt
3. Display the last few lines of multiple files:
3. Display the last few lines of multiple files:
tail file1.txt file2.txt
4. Display the last 5 lines of all .log files in a directory:
4. Display the last 5 lines of all .log files in a directory:
tail -n 5 *.log
5. Display the last 15 lines of a remote file using SSH:
5. Display the last 15 lines of a remote file using SSH:
ssh user@hostname "tail -n 15 /path/to/remote/file.txt"
6. Display the last lines of a file and continuously update as new lines are added (useful for log files):
6. Display the last lines of a file and continuously update as new lines are added (useful for log files):
tail -f filename.log
Remember that the tail command is used to display the ending lines of a file. If you want to view the beginning lines, you can use the `head` command.
Remember that the tail command is used to display the ending lines of a file. If you want to view the beginning lines, you can use the `head` command.
No comments:
Post a Comment