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.
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 .
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.
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.
ls | grep -v unwanted | xargs tail -f
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With