系统之家 - 系统光盘下载网站!

当前位置:系统之家 > 系统教程 > Linux find命令-exec参数的作用

Linux find命令中-exec参数的作用(3)

时间:2014-12-31 18:02:54 作者:qipeng 来源:系统之家 1. 扫描二维码随时看资讯 2. 请使用手机浏览器访问: https://m.xitongzhijia.net/xtjc/20141231/33889.html 手机查看 评论

  实例5:查找文件移动到指定目录

  命令:

  find 。 -name “*.log” -exec mv {} 。。 \;

  输出:

  代码如下:

  [root@localhost test]# ll

  总计 12drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxr-x 2 root root 4096 11-12 22:49 test3

  drwxrwxr-x 2 root root 4096 11-12 19:32 test4

  [root@localhost test]# cd test3/

  [root@localhost test3]# ll

  总计 304

  -rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log

  -rw-r--r-- 1 root root 61 11-12 22:44 log2013.log

  -rw-r--r-- 1 root root 0 11-12 22:25 log2014.log

  [root@localhost test3]# find 。 -name “*.log” -exec mv {} 。。 \;

  [root@localhost test3]# ll

  总计 0[root@localhost test3]# cd 。。

  [root@localhost test]# ll

  总计 316

  -rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log

  -rw-r--r-- 1 root root 61 11-12 22:44 log2013.log

  -rw-r--r-- 1 root root 0 11-12 22:25 log2014.log

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxr-x 2 root root 4096 11-12 22:50 test3

  drwxrwxr-x 2 root root 4096 11-12 19:32 test4

  [root@localhost test]#

  实例6:用exec选项执行cp命令

  命令:

  find 。 -name “*.log” -exec cp {} test3 \;

  输出:

  代码如下:

  [root@localhost test3]# ll

  总计 0[root@localhost test3]# cd 。。

  [root@localhost test]# ll

  总计 316

  -rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log

  -rw-r--r-- 1 root root 61 11-12 22:44 log2013.log

  -rw-r--r-- 1 root root 0 11-12 22:25 log2014.log

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxr-x 2 root root 4096 11-12 22:50 test3

  drwxrwxr-x 2 root root 4096 11-12 19:32 test4

  [root@localhost test]# find 。 -name “*.log” -exec cp {} test3 \;

  cp: “。/test3/log2014.log” 及 “test3/log2014.log” 为同一文件

  cp: “。/test3/log2013.log” 及 “test3/log2013.log” 为同一文件

  cp: “。/test3/log2012.log” 及 “test3/log2012.log” 为同一文件

  [root@localhost test]# cd test3

  [root@localhost test3]# ll

  总计 304

  -rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log

  -rw-r--r-- 1 root root 61 11-12 22:54 log2013.log

  -rw-r--r-- 1 root root 0 11-12 22:54 log2014.log

  [root@localhost test3]#

  上面就是Linux find命令中-exec参数的用法介绍了,find命令的参数还有很多,如果你还想了解其他参数的使用,详见系统之家Linux find命令中-path -prune参数的作用介绍

发表评论

0

没有更多评论了

评论就这些咯,让大家也知道你的独特见解

立即评论

以上留言仅代表用户个人观点,不代表系统之家立场

其他版本软件

热门教程

人气教程排行

Linux系统推荐

官方交流群 软件收录