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

当前位置:系统之家 > 系统教程 > 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系统推荐

官方交流群 软件收录