find命令扩展

1.1 方法一   |xargs

通过|xargs将前面命令的执行结果传给后面。

[root@znix ~]# find /clsn/ -type f -name "*.sh" |xargs ls -l

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/test/del.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /clsn/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/t.sh

1.2 方法二   $()

$()先运行里面的命令,把显示到屏幕上的结果留下来

[root@znix ~]# ls -l $(find /clsn/ -type f -name "*.sh")

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/test/del.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /clsn/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/t.sh

1.3 方法三   -exec {} ;

-exec 是find 里面自带参数,{}表示find命令找到的文件

[root@znix ~]# find /clsn/ -type f -name "*.sh" -exec ls -l {} ;

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/t.sh

-rw-r--r--. 1 root root 8 Aug 17 19:35 /clsn/test.sh

-rw-r--r--. 1 root root 7 Aug 17 17:00 /clsn/test/del.sh

原文地址:https://www.cnblogs.com/liuyuanq/p/9695715.html