我们一般会使用find来查找文件,用echo来查找文件你用过吗?
比如在ports里面查找screen:
root@10:/usr/ports# echo /usr/ports/*/*screen*
/usr/ports/distfiles/screen-4.2.1.tar.gz /usr/ports/graphics/kipi-plugin-debianscreenshots /usr/ports/misc/elscreen /usr/ports/net/p5-Net-Telnet-Netscreen /usr/ports/sysutils/screen /usr/ports/sysutils/screen-legacy /usr/ports/sysutils/screenfetch /usr/ports/sysutils/screenie /usr/ports/x11-fonts/font-screen-cyrillic /usr/ports/x11-toolkits/p5-Tk-Splashscreen /usr/ports/x11-wm/e17-module-screenshot /usr/ports/x11/gnome-screensaver /usr/ports/x11/mate-screensaver /usr/ports/x11/printscreen /usr/ports/x11/xfce4-screenshooter-plugin /usr/ports/x11/xscreensaver /usr/ports/x11/xscreensaver-gnome /usr/ports/x11/xscreensaver-gnome-hacks /usr/ports/x11/xscreensaver.app
注意不分行,一行会有超过两个结果。
但是这种方法有个限制,就是每个“*/”组合只能代表一组目录,看下面的例子,在src里找ath.c结尾的文件,不同数量的“*/”会有不同的结果:
root@10:/usr/src # echo /usr/src/*/*ath.c
echo: No match.
root@10:/usr/src # echo /usr/src/*/*/*ath.c
/usr/src/bin/realpath/realpath.c /usr/src/contrib/bmake/realpath.c /usr/src/contrib/gcc/c-incpath.c /usr/src/lib/libutil/_secure_path.c /usr/src/sys/net/radix_mpath.c /usr/src/usr.bin/patch/mkpath.c
root@10:/usr/src # echo /usr/src/*/*/*/*ath.c
/usr/src/contrib/binutils/libiberty/lrealpath.c /usr/src/contrib/gcclibs/libiberty/lrealpath.c /usr/src/contrib/ntp/ntpd/refclock_heath.c /usr/src/contrib/sendmail/libsm/path.c /usr/src/contrib/sendmail/libsm/t-path.c /usr/src/crypto/openssh/openbsd-compat/realpath.c /usr/src/lib/libc/rpc/getnetpath.c /usr/src/lib/libc/stdlib/realpath.c /usr/src/sys/dev/ath/if_ath.c /usr/src/sys/geom/multipath/g_multipath.c
root@10:/usr/src # echo /usr/src/*/*/*/*/*ath.c
/usr/src/contrib/apr/file_io/unix/filepath.c /usr/src/contrib/gcc/config/i386/crtfastmath.c /usr/src/contrib/gcc/config/ia64/crtfastmath.c /usr/src/contrib/gcc/config/sparc/crtfastmath.c /usr/src/contrib/libarchive/libarchive/test/test_archive_match_path.c /usr/src/contrib/libarchive/libarchive/test/test_write_format_mtree_absolute_path.c /usr/src/contrib/libarchive/tar/test/test_print_longpath.c /usr/src/contrib/subversion/subversion/libsvn_subr/path.c /usr/src/contrib/wpa/src/tls/libtommath.c /usr/src/crypto/heimdal/lib/krb5/expand_path.c /usr/src/sbin/geom/class/multipath/geom_multipath.c /usr/src/sys/dev/usb/wlan/if_uath.c /usr/src/sys/dev/vxge/vxgehal/vxgehal-virtualpath.c /usr/src/tools/regression/include/tgmath/tgmath.c
root@10:/usr/src # echo /usr/src/*/*/*/*/*/*ath.c
echo: No match.
结论:
在明确知道某个目录下、特别是还有很多子级目录的时候,比如ports树,这种用法效率是非常高的,因为它不需要进入每一个下级子目录。