find命令查找含有软连接目录的文件夹

我们知道find命令是linux下比较强大的查找命令,使用也非常复杂,不仅能查找还能使用exec选项进行进一步对文件的操作,如压缩、删除、grep等。可以说是linux运维居家旅行必备神器。

但是最近在使用该命令时发现其对软连接文件夹会当做文件进行操作,而不是进入该“文件夹”然后递归查询。

下面举例进行演示,首先我们建立如下结构的文件

root@kali:~/test# pwd
/root/test
                                                                                                                                                                                                                                         
root@kali:~/test# tree
.
├── a
│   └── a1
│       └── a2
│           └── a.txt
├── b
│   └── b1
│       └── b2
│           └── b.txt
└── root.txt

6 directories, 3 files
                                                                                                                                                                                                                                         
root@kali:~/test# find /root/test  -name "*.txt" 
/root/test/b/b1/b2/b.txt
/root/test/root.txt
/root/test/a/a1/a2/a.txt
                        

根据结果显示,我们可以查到所有的txt文件。我们在test目录下建立一个软连接。

root@kali:~/test# pwd 
/root/test
                                                                                                                                                                                                                                         
root@kali:~/test# tree
.
├── a
│   └── a1
│       └── a2
│           └── a.txt
├── b
│   └── b1
│       └── b2
│           └── b.txt
├── linkDir -> /root/test1 ##我们新建的链接文件
└── root.txt

7 directories, 3 files
                                                                                                                                                                                                                                         
root@kali:~/test# tree /root/test1     #链接文件夹的结构    
/root/test1
├── ls_a1.txt
├── ls_a2.txt
└── test2
    └── ls_a3.txt

1 directory, 3 files
                                                                                                                                                                                                                                         
root@kali:~/test# 

我们使用find命令进行查找看看结果如何?

root@kali:~/test# find /root/test  -name "*.txt" 
/root/test/b/b1/b2/b.txt
/root/test/root.txt
/root/test/a/a1/a2/a.txt
                                                                                                                                                                                                                                         
root@kali:~/test# #结果并不是我们想要的

啥情况 怎么整呢?  其实链接文件不管target是什么,它只是个文件,就叫链接文件。

通过ll领了可以看到:第一列是ddl-  。这应该就是为啥find命令没有进一步递归进去查询的原因(我猜的)。那如果我们想也查到软链接文件里的文件咋整呢?

尝试第一种写法:貌似可以查到了,但是root.txt没了啊。。。

root@kali:~/test# find ./*/  -name "*.txt"        
./a/a1/a2/a.txt
./b/b1/b2/b.txt
./linkDir/ls_a2.txt
./linkDir/ls_a1.txt
./linkDir/test2/ls_a3.txt

 我们只好查find命令的手册了,使用info find。

 'find' searches the directory tree rooted at each file name FILE by
evaluating the EXPRESSION on each file it finds in the tree.

--------递归的查呗

'-P'
     Never follow symbolic links (this is the default), except in the
     case of the '-xtype' predicate.
'-L'
     Always follow symbolic links, except in the case of the '-xtype'
     predicate.
'-H'
     Follow symbolic links specified in the list of files to search, or
     which are otherwise specified on the command line.                                                                                                                                                

 完蛋了,这不写的很清楚嘛,我们抓紧试试。如下,诚不我欺啊。。。 加上-L 选项即可。

root@kali:~/test# find -L  -name "*.txt"   
./b/b1/b2/b.txt
./root.txt
./a/a1/a2/a.txt
./linkDir/ls_a2.txt
./linkDir/ls_a1.txt
./linkDir/test2/ls_a3.txt
                                                                                     
root@kali:~/test# 

那我们来统计一下/usr/share/wordlist里各个密码字典的密码行数吧。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值