Use the tail +1877(698)-1665 Command on Linux
The Linux tail command displays data from the end of a file. It can even show updates being added to a file in real time. We show you how to use it.
The tail command shows you data from the end of a file. New data is usually added to the end of a file, so the tail command is a quick and easy way to see the most recent additions to a file. You can also monitor a file and display each new text entry in that file as they occur. This makes it a great tool for monitoring log files.
Many modern Linux distributions have adopted the systemd systems and services manager. This is the first process executed, has process ID 1, and is the parent of all other processes. This function used to be handled by the previous init system.
Along with this change came a new format for system log files. They are no longer created in plain text, in systemd they are recorded in binary format. To read these log files, you must use the journactl utility. The tail command works with plain text formats. Does not read binary files. So does this mean that the tail command is a solution in search of a problem? Do you still have something to offer?
The tail command is more than just showing real-time updates. And in fact, there are still many log files that are not generated by the system and are still created as plain text files. For example, log files generated by applications have not changed their format.
Pass a file name to tail and it will show you the last ten lines of that file. The example files we are using contain ordered lists of words. Each line is numbered, so it should be easy to follow the examples and see what effect different options have.
To view a different number of lines, use the -n (number of lines) option:
You can actually do without the “-n” and just use a hyphen “-” and the number. Make sure there are no spaces between them. Technically this is a deprecated command form, but it’s still on the man page and still works.
You can have the queue work with multiple files at once. Simply pass the file names on the command line:
A small header is displayed for each file so you know which file the lines belong to.
The + (count from start) modifier causes tail lines to be displayed from the start of a file, starting at a specific line number. If your file is very long and you choose a line near the beginning of the file, you will receive a large number of results sent to the terminal window. If that’s the case, it makes sense to pipe the queue output to less.
You can skim the text in a controlled manner.
Because there are 20,445 lines in this file, this command is equivalent to using the “-6” option:
You can tell tail to use offsets in bytes instead of lines using the -c (bytes) option. This might be useful if you have a text file formatted in normal-sized records. Note that one newline character counts as one byte. This command will display the last 93 bytes of the file:
You can combine the -c (bytes) option with the + (count from start of file) switch and specify an offset in bytes counted from the start of the file:
Previously, we piped the output of tail to less . We can also pipe the output of other commands to tail.
To identify the five files or folders with the oldest modification times, use the -t (sort by modification time) option with ls and pipe the output to tail.
The head command lists lines of text from the beginning of a file. We can combine this with tail to extract a section of the file. Here, we use the head command to extract the first 200 lines of a file. This is piped to tail, which extracts the last ten lines. This gives us lines 191 to line 200. That is, the last ten lines of the first 200 lines:
This command lists the five processes that consume the most memory.
Let’s analyze that.
Tracking new text entries that arrive in a file (usually a log file) is easy with tail. Pass the file name on the command line and use the -f (follow) option.
As each new log entry is added to the log file, tail updates its display in the terminal window.
You can refine the result to include only lines of particular relevance or interest. Here, we use grep to display only lines that include the word “average”:
Although access to system log files is now provided by journalctl, tail still has a lot to offer. This is especially true when used in conjunction with other commands, piping in or out of the queue.
Systemd may have changed the landscape, but there is still a place for traditional utilities that fit the Unix philosophy of doing one thing and doing it well.
Source Url:
https://medium.com/@rc9338288/how-to-use-the-tail-command-on-linux-1547f9a4193f