linux的find和作用,linux中find命令中-path 参数的作用中文介绍

find命令中-path 参数的作用(意思)解释

-path pattern

File name matches shell pattern pattern. The metacharacters do not treat /' or .' specially; so, for example,

find . -path './sr*sc'

will print an entry for a directory called './src/misc' (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory `src/emacs' and all files and directories under it, and print the names of the other files found, do something like this:

find . -path './src/emacs' -prune -o -print

意思就是说,find命令中用了-path 参数,则文件名是匹配shell通配符模式。这时候,元字符不能识别 '/ '  和 ' . '  。举个例子

假设/root 目录下有四个文件,其绝对路径分别为:

/root/src/misc

/root/src/test/misc

/root/src1misc

/root/test/src/misc

这时候输入下面的命令:

[root@dabu.info ~]# cd  /root

[root@dabu.info ~]#find . -path   './sr*sc'

./src1misc

./src/misc

./src/test/misc

命令运行输出的结果不是文件名,而是文件的路径

可见,文件夹符号/  在此时也可以用 * 通配符匹配,而且 * 是可以匹配n多个字符。上面的命令行的意思是是在当前目录下及子目录递归查找文件路径 匹配的文件,所以输出的是文件的路径。

因为是'./sr*sc'  ,所以 /root/test/src/misc这个文件不匹配,因为  ./   代表当前目录 (即/root) ,而 /root/test/src/misc不符合 ./sr的格式。

但是稍微改一下,如下:

[root@dabu.info ~]#find  .  -path  '*/sr*sc*'

./src1misc

./src/misc

./src/test/misc

./test/src/misc

解释:因为" * " 可以匹配 "." 和  "  / ", 我们将上面的'*/sr*sc*'  改为  '*sr*sc*'   。结果也是一样的。

注意:也可以直接用绝对路径

[root@dabu.info ~]#find /root   -path  '*/sr*sc*'

[root@dabu.info ~]#find  /root   -path  '/root/sr*sc*'

/root/src1misc

/root/src/misc

/root/src/test/misc

此时, /root/test/src/misc 是不符的'/root/sr*sc*'的格式的。

所以Linux / Unix:递归查找并列出所有(全部)隐藏文件的方法可以如下:

[root@dabu.info ~]#find  /要查找的文/件/夹/     -path  '*/.*'   -print

教程完!

-path更多的是配合 -prune -o  来在操作时排除指定的文件。这里就不说了,大家自行百度去吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值