find命令查找文件忽略指定或者匹配目录

本地有如下一个目录,需要查找所有文件并忽略.git目录

$ tree -a
.
├── a
│   └── bcd.txt
├── abc.txt
├── b
│   └── ccd.txt
├── c
│   ├── ccb.txt
│   └── .git
│       └── a
│           └── bcd.txt
└── .git
    └── a
        └── bcd.txt

7 directories, 6 files

使用命令即可:find . -type f -not -path '**/.git/**' -print

$ find . -type f -not -path '**/.git/**' -print
./b/ccd.txt
./a/bcd.txt
./abc.txt
./c/ccb.txt

如果忽略匹配多个目录,追加-not -path即可,如下:

$ find . -type f -not -path '**/.git/**' -not -path '**/a/**' -print
./b/ccd.txt
./abc.txt
./c/ccb.txt

猜你喜欢

转载自blog.csdn.net/liurizhou/article/details/88884674