- 论坛徽章:
- 0
|
[root@localhost hoho]# ls -l ./
total 0
lrwxrwxrwx 1 root root 7 Jan 5 08:06 bin -> usr/bin
dr-xr-xr-x 2 root root 40 Jul 8 04:56 boot
drwxr-xr-x 2 root root 40 Jul 8 04:56 dev
drwxr-xr-x 12 root root 700 Jan 5 08:06 etc
drwxr-xr-x 2 root root 40 Jul 8 04:56 home
lrwxrwxrwx 1 root root 7 Jan 5 08:06 lib -> usr/lib
drwxr-xr-x 2 root root 40 Jul 8 04:56 media
drwxr-xr-x 2 root root 40 Jul 8 04:56 mnt
drwxr-xr-x 2 root root 40 Jul 8 04:56 opt
dr-xr-xr-x 2 root root 40 Jul 8 04:56 proc
dr-xr-x--- 2 root root 40 Jul 8 04:56 root
drwxr-xr-x 2 root root 40 Jul 8 04:56 run
lrwxrwxrwx 1 root root 8 Jan 5 08:06 sbin -> usr/sbin
drwxr-xr-x 2 root root 40 Jul 8 04:56 srv
drwxr-xr-x 2 root root 40 Jul 8 04:56 sys
drwxrwxrwt 2 root root 40 Jul 8 04:56 tmp
drwxr-xr-x 12 root root 260 Jan 5 08:06 usr
drwxr-xr-x 18 root root 400 Jan 5 08:06 var
上述目录有三个符号链接 sbin , bin ,lib
然后分别测试以下三个命令都没问题,
- find ./ -maxdepth 1 -type d
- find ./ -maxdepth 1 -type l
- find ./ -maxdepth 1 -type d -o -type l
复制代码
但以下命令就得不到期望的效果了(期望的结果是找到 目录 或者 符号链接 并执行某一命令)
- find ./ -maxdepth 1 -type d -o -type l -exec echo {} \;
复制代码
这命令的结果好像仅由后一个 -type 指定了,即该例中只输出符号链接,
另外测试发现, 如果两个 -type 指定相同类型时,
-type d -o -type d
-type l -o -type l
一旦加上 -exec 选项, 没结果输出了?! (平台: fedora 19, findutils-4.5.11-1.fc19.i686, archlinux findutils 4.4.2-5 都测过)
大牛们, 请教一下这是什么原因呢 ? 还是我的命令有错误呢 ?
好像有见过帖子介绍 xargs 时说过是跟 find 传递搜索到的结果的方式有关, 但找不到了,无法求证...
特再发贴求高人解惑. 先谢过了.
测试结果如下, 有点长:
- [root@localhost hoho]# find ./ -maxdepth 1 -type d
- ./
- ./tmp
- ./sys
- ./srv
- ./root
- ./proc
- ./opt
- ./mnt
- ./media
- ./home
- ./dev
- ./boot
- ./etc
- ./run # 全是目录类型,OK
- ./usr
- ./var
- [root@localhost hoho]# find ./ -maxdepth 1 -type l
- ./sbin
- ./lib # 都是符号链接, OK
- ./bin
- [root@localhost hoho]# find ./ -maxdepth 1 -type d -o -type l
- ./
- ./tmp
- ./sys
- ./srv
- ./sbin
- ./root
- ./proc
- ./opt
- ./mnt
- ./media
- ./lib
- ./home
- ./dev
- ./boot
- ./bin # 有目录,有符号链接.也正确
- ./etc
- ./run
- ./usr
- ./var
- [root@localhost hoho]# find ./ -maxdepth 1 -type d -o -type l -exec echo {} \;
- ./sbin
- ./lib # ?, 说好的 -type d 呢?
- ./bin
- [root@localhost hoho]# find ./ -maxdepth 1 -type l -o -type d -exec echo {} \;
- ./
- ./tmp
- ./sys
- ./srv
- ./root
- ./proc
- ./opt
- ./mnt
- ./media
- ./home # ? 说好的 -type l 呢?
- ./dev
- ./boot
- ./etc
- ./run
- ./usr
- ./var
- [root@localhost hoho]# find ./ -maxdepth 1 -type l -o -type l -exec echo {} \;
- [root@localhost hoho]# 啥都没了 ?
复制代码
|
|