linux find 多个条件,并将结果复制到某个文件夹

628 阅读1分钟

linux 的 find 命令用来查找文件或者文件夹,

基本格式如下:

find 搜索路径 选项 搜索内容
  • 第一个参数用来指定搜索路径;
  • 第二个参数用来指定搜索内容。

如果需要使用多个搜索条件并且条件之前是或的关系,是条件之后加上 -o,如下

find /home/cloud/ -name 'clou*.jar' -o -name '*.sh' -o -name 'conf'

可以加上文件查找的深度 -maxdepth

find /home/cloud/ -maxdepth 2 -name 'clou*.jar' -o -name '*.sh' -o -name 'conf'

将查查找的结果复制到某个目录下

find /home/cloud/ -maxdepth 2 -name 'clou*.jar' -o -name '*.sh' -o -name 'conf' -exec cp --parents {} . \;

--parents 表示保存源文件的目录结构。