linux基础之find命令常用用法

一、根据文件名查找文件

  • 1.在当前目录中根据文件名(完整文件名)查找文件(若是目录文件,则打印目录下所有文件)
    只是在当前目录查找,不会遍历当前目录下的目录文件
#在当前目录查找1.c文件
linux@ubuntu:~$ find 1.c
1.c
#在当前目录查找后缀为.txt的所有文件
linux@ubuntu:~$ find *.txt
testtest.txt
test.txt
#在当前目录查找以test开头的所有文件
linux@ubuntu:~$ find test*
test
test/inc
test/inc/match_bmp.h
test/inc/touch.h
test/inc/bmp.h
test/bin
test/bin/main
test/src
test/src/touch.c
test/src/bmp.c
test/src/match_bmp.c
test/src/main.c
test/Makefile
testtest.txt
test.txt
  • 2.查找指定目录下的文件
#在当前目录下的test/src/目录查找后缀为“.c”的所有文件
linux@ubuntu:~$ find test/src/ -name '*.c'
test/src/touch.c
test/src/bmp.c
test/src/match_bmp.c
test/src/main.c
  • 3.使用名称和忽略案例查找文件
#在当前目录找到名称为test的所有文件,不区分大小写
linux@ubuntu:~/test$ find ./ -iname test
./Test
./test
  • 4.使用名称查找.c文件
#在当前工作目录中查找所有.c文件。
linux@ubuntu:~/test$ find ./ -type f -name '*.c'
./src/touch.c
./src/bmp.c
./src/match_bmp.c
./src/main.c
./bmp.c
posted @ 2019-12-16 20:25  pxysource  阅读(543)  评论(0编辑  收藏  举报