Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tail command -f on all files excluding a file

Tags:

bash

I want to run tail -f command on all the file in a directory except one file in that directory. Can somebody suggest me a way of doing it thanks.

like image 875
Sujith Ej Avatar asked Sep 16 '13 06:09

Sujith Ej


People also ask

How do you break tail command?

In less , you can press Ctrl-C to end forward mode and scroll through the file, then press F to go back to forward mode again. Note that less +F is advocated by many as a better alternative to tail -f .

How do you use the tail command?

Tail command also comes with an '+' option which is not present in the head command. With this option tail command prints the data starting from specified line number of the file instead of end. For command: tail +n file_name, data will start printing from line number 'n' till the end of the file specified.

What will tail 10 command do?

Now apply the tail command on this file. This command will fetch the last 10 lines of the record. The 10 number is constant. So if you do not provide a specific number, then the system by default considers it as 10.


2 Answers

       ls | grep -v unwanted | xargs tail -f
like image 94
SF. Avatar answered Oct 07 '22 00:10

SF.


You could also use the exec flag with find to give you a nice cohesive one liner:

find . -maxdepth 1 -type f ! -name unwanted.txt -exec tail -f {} +

You can also play around with the -maxdepth flag if you want to go more than the current directory in depth or omit it completely if you wanted to recurse through the current directory and all sub directories.

You can also add other excluded files by using the -a flag like so:

find . -maxdepth 1 -type f ! -name unwanted.txt -a -type f ! -name unwanted2.txt -exec tail -f {} +

However that could get a little tedious for an extended amount of files.

like image 30
Bryan Avatar answered Oct 06 '22 22:10

Bryan