[英]Copy all files excluding one file in shell script
I am new to shell scripting. 我是shell脚本的新手。
I have a command which copies all tml/xml
files in the current directly to another as below: 我有一个命令将当前的所有tml/xml
文件直接复制到另一个,如下所示:
cp -f *.[tx]ml $path
But I need to exclude one file (excludeme.xml) while executing the above command. 但是我需要在执行上述命令时排除一个文件(excludeme.xml)。
I tried the below command but did not work. 我尝试了以下命令,但没有奏效。
find . -name "excludeme.xml" | xargs -0 -I {} cp -f *.[tx]ml $path
Try: 尝试:
find . ! -name excludeme.xml | ...
or 要么
ls *.[tx]ml | while read -r file; do test x"$file" = xexcludeme.xml || cp -f "$file" "$path" done
Note the leading 'x'; 注意领先的'x'; it is probably not necessary in modern shells, but will prevent errors when the file name begins with '-'. 在现代shell中可能没有必要,但是当文件名以“ - ”开头时会阻止错误。
If this is bash
then 如果这是bash
那么
shopt -s extglob
cp !(excludeme).[tx]ml destination
ls *.[tx]ml | grep -v excludeme.xml | xargs cp -f -t $path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.