Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何避免使用cp命令复制特定的文件格式_Bash_Shell - Fatal编程技术网

Bash 如何避免使用cp命令复制特定的文件格式

Bash 如何避免使用cp命令复制特定的文件格式,bash,shell,Bash,Shell,我正在MaBash脚本中使用cp命令 cp /source/* /destination 我只是想避免将所有.txt文件从源文件复制到目标文件。我不知道是否可以在copy中执行此操作,但rsync命令具有此功能。试一试 rsync-av/source/*/destination-exclude*txt 有关更多详细信息和示例,请参见 我不知道您是否可以在copy中执行此操作,但rsync命令具有此功能。试一试 rsync-av/source/*/destination-exclude*txt

我正在MaBash脚本中使用cp命令

cp /source/* /destination 

我只是想避免将所有.txt文件从源文件复制到目标文件。

我不知道是否可以在copy中执行此操作,但rsync命令具有此功能。试一试

rsync-av/source/*/destination-exclude*txt


有关更多详细信息和示例,请参见

我不知道您是否可以在copy中执行此操作,但rsync命令具有此功能。试一试

rsync-av/source/*/destination-exclude*txt


有关更多详细信息和示例,请参见

如果启用了扩展球形化,则可以匹配除txt文件以外的所有文件:

cp /source/!(*.txt) /destination

*.txt与所有txt文件匹配。这个告诉它匹配所有的东西,除了。。。零件。

如果启用了扩展球形化,则可以匹配除txt文件以外的所有文件:

cp /source/!(*.txt) /destination
*.txt与所有txt文件匹配。这个告诉它匹配所有的东西,除了。。。零件。

试试看

find . -maxdepth 1 -type f \( ! -iname "*.txt" \) -print0 | xargs -0 cp {} /destination
需要-print0和-0来处理名称中可能有空格的文件。

请尝试

find . -maxdepth 1 -type f \( ! -iname "*.txt" \) -print0 | xargs -0 cp {} /destination

需要-print0和-0来处理名称中可能有空格的文件。

bash:!:在shopt-s extglob之后没有找到事件。当我在脚本中写入时,它不起作用,有什么想法吗?你接受卡米尔的建议了吗?bash:!:在shopt-s extglob之后,事件未被发现。当我在脚本中写入时,它不起作用,知道吗?你接受Kamil的建议了吗?