8

我想对该目录中的所有文件运行 tail -f 命令,但该目录中的一个文件除外。有人可以建议我一种方法吗谢谢。

4

3 回答 3

11
       ls | grep -v unwanted | xargs tail -f
于 2013-09-16T06:55:51.017 回答
1

你也可以使用execflag withfind给你一个很好的凝聚力的一个衬里:

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

-maxdepth如果您想深入当前目录,也可以使用该标志,或者如果您想递归遍历当前目录和所有子目录,则完全省略它。

您还可以使用以下-a标志添加其他排除文件:

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

但是,对于大量文件来说,这可能会有点乏味。

于 2013-09-16T07:37:51.920 回答
0

您可以使用 bash 的扩展 globbing,例如:

$ 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
于 2013-09-16T08:17:07.713 回答