The tail command -f for all files excluding the file

I want to run the tail -f command for the entire file in the directory, except for one file in this directory. Can someone suggest me a way to do this thanks.

+6
source share
3 answers
ls | grep -v unwanted | xargs tail -f 
+7
source

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

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

You can also play with the -maxdepth flag if you want to navigate more than the current directory, or completely omit it if you want to overwrite the current directory and all subdirectories.

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

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

However, this can be a little tedious for a large number of files.

+1
source

You can use bash extended push , for example:

 $ shopt -s extglob $ ll total 20K drwxr-xr-x 2 foo foo 4.0K Sep 16 10:15 ./ drwxr-xr-x 5 foo foo 4.0K Sep 16 10:14 ../ -rw-r--r-- 1 foo foo 2 Sep 16 10:15 one -rw-r--r-- 1 foo foo 2 Sep 16 10:15 three -rw-r--r-- 1 foo foo 2 Sep 16 10:15 two $ ll !(three) -rw-r--r-- 1 foo foo 2 Sep 16 10:15 one -rw-r--r-- 1 foo foo 2 Sep 16 10:15 two $ tail * ==> one <== 1 ==> three <== 3 ==> two <== 2 $ tail !(three) ==> one <== 1 ==> two <== 2 
0
source

Source: https://habr.com/ru/post/953893/


All Articles