Linux find命令与xargs组合使用的方法(2) - 万象系统之家

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

当前位置:万象系统之家 > 系统教程 > Linux find命令与xargs组合使用

Linux find命令与xargs组合使用的方法(2)

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

  实例3:在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限

  命令:

  代码如下:

  find 。 -perm -7 -print | xargs chmod o-w

  输出:

  代码如下:

  [root@localhost test]# ll

  总计 312

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

  -rw-r--r-- 1 root root 0 11-12 22:25 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

  drwxrwxrwx 2 root root 4096 11-12 19:32 test3

  drwxrwxrwx 2 root root 4096 11-12 19:32 test4

  [root@localhost test]# find 。 -perm -7 -print | xargs chmod o-w

  [root@localhost test]# ll

  总计 312

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

  -rw-r--r-- 1 root root 0 11-12 22:25 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 19:32 test3

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

  [root@localhost test]#

  说明:

  执行命令后,文件夹scf、test3和test4的权限都发生改变

  实例4:用grep命令在所有的普通文件中搜索hostname这个词

  命令:

  代码如下:

  find 。 -type f -print | xargs grep “hostname”

  输出:

  代码如下:

  [root@localhost test]# find 。 -type f -print | xargs grep “hostname”

  。/log2013.log:hostnamebaidu=baidu.com

  。/log2013.log:hostnamesina=sina.com

  。/log2013.log:hostnames=true[root@localhost test]#

  实例5:用grep命令在当前目录下的所有普通文件中搜索hostnames这个词

  命令:

  代码如下:

  find 。 -name \* -type f -print | xargs grep “hostnames”

  输出:

  代码如下:

  [root@peida test]# find 。 -name \* -type f -print | xargs grep “hostnames”

  。/log2013.log:hostnamesina=sina.com

  。/log2013.log:hostnames=true[root@localhost test]#

  说明:

  注意,在上面的例子中, \用来取消find命令中的*在shell中的特殊含义。

发表评论

0

没有更多评论了

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

立即评论

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

Linux系统推荐

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版系统!

如侵犯到您的权益,请及时通知我们,我们会及时处理,对系统之家有任何投诉或建议,请与管理员联系. QQ:346231061

Copyright2024 万象系统之家(www.maxdo.tech) 版权所有 沪ICP备2021023961号-5 粤公网安备 13010202004188