我想复制一个目录中的所有文件,除了特定子目录中的一些文件。 我注意到cp命令没有——exclude选项。 那么,我怎么才能做到呢?
当前回答
rsync
rsync -r --verbose --exclude 'exclude_pattern' ./* /to/where/
首先用-n选项试试,看看会复制什么
其他回答
Rsync无法使用。下面是一个可行的替代方案。
tar -cf - --exclude='./folder' --exclude='./file.tar' ./source_directory | tar -xf - -C ./destination_directory
mv tobecopied/tobeexcluded .
cp -r tobecopied dest/
mv tobeexcluded tobecopied/
cp -r `ls -A | grep -v "Excluded_File_or_folder"` ../$target_location -v
为什么要使用rsync,当你可以:
find . -type f -not -iname '*/not-from-here/*' -exec cp '{}' '/dest/{}' ';'
这假设目标目录结构与源目录结构相同。
这是对Linus Kleen的回答的修改。他的回答对我没用,因为会有。添加在cp不喜欢的文件路径前面(路径看起来像source/.destination/file)。
这个命令对我很管用:
找到。-type f -not -path '*/ exclude -path/*' -exec cp——parents '{}' '/destination/' \;
——parents命令保留目录结构。
推荐文章
- 如何从终端机发送电子邮件?
- 如何将文件指针(file * fp)转换为文件描述符(int fd)?
- Linux Bash中双&和分号有什么区别?
- 在Bash中模拟do-while循环
- 在Bash中将输出赋给变量
- 在SSH会话中查找客户端的IP地址
- C++ Linux的想法?
- 如何为Fedora安装g++ ?
- 如何在Mac OS X 10.6中使硬件发出哔哔声
- Linux删除大小为0的文件
- Node.js同步执行系统命令
- 从Docker容器获取环境变量
- Spring引导应用程序作为服务
- 如何重定向标准derr和标准输出到不同的文件在同一行脚本?
- Windows和Linux上的c++编译:ifdef开关