How to monitor multiple files?

099

To monitor multiple files using tail, you can use the -f option with multiple file names. Here’s how to do it:

Command Syntax:

tail -f file1 file2 file3

Example:

If you want to monitor two log files, for instance, app.log and error.log, you would run:

tail -f app.log error.log

Output:

This command will display the last 10 lines of both files and continue to show new lines as they are added to either file.

Additional Options:

  • Using Wildcards: You can also use wildcards to monitor multiple files that match a pattern:

    tail -f /var/log/*.log

    This will monitor all .log files in the /var/log/ directory.

  • Using -n Option: If you want to specify how many lines to show initially, you can combine it with -f:

    tail -n 20 -f app.log error.log

    This will show the last 20 lines of each file before following new entries.

If you have further questions or need more examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!