find命令可以按照指定的规则对硬盘上的文件进行查找,且可以跨越不同的文件系统。find命令的使用方法:
1 | find fold [option] |
下面按照不同的选项介绍find命令。
find -name
-name是最常用的选项,它指定了需要查找的文件名的模式,模式中可以使用通配符和简单的正则表达式。下面的命令查找Wdir目录下的.cpp文件:
1 2 3 4 5 6 7 8 9 10 11 | dutor@dutor-desktop:~$ find Wdir -name "*.cpp" Wdir/Cpp/Pthread/main.cpp Wdir/Cpp/STL/sort_list.cpp Wdir/Cpp/STL/Heap.cpp Wdir/Cpp/STL/operator.cpp Wdir/Cpp/STL/bind2nd/main.cpp Wdir/Cpp/STL/Kth-Max.cpp Wdir/Cpp/STL/priority_queue.cpp Wdir/Cpp/ACM/Huffman/main.cpp Wdir/Cpp/ACM/Bellman-Ford/main.cpp ...... |
需要注意的是,如果搜索目录以相对路径形式指定,则搜索结果也以相对路径形式给出;否则,搜索结果以绝对路径形式给出。