[英]In Linux, how to copy all the files not starting with a given string?
I tried with the following command: 我尝试使用以下命令:
cp src_folder/[!String]* dest_folder
However, this command will copy all the files that don't start with any of the characters 'S','t','r','i','n','g' instead of copying files that don't start with "String". 但是,此命令将复制所有不以任何字符'S','t','r','i','n','g'开头的文件,而不是复制不复制的文件以“String”开头。
A variation on Konrad answer, using cp
option -t
to specify target directory simplifies the last command. Konrad回答的变体,使用
cp
选项-t
指定目标目录简化了最后一个命令。 It creates a single cp
process to copy all the files. 它创建一个单独的
cp
进程来复制所有文件。
ls src_folder | grep -v '^String' | xargs cp -t dest_folder
src_folder
src_folder
中的所有文件 String
String
开头的东西 dest_dir
dest_dir
In bash: 在bash中:
shopt -s extglob
cp src_folder/!(String*) dest_folder
ls src_folder | grep -v '^String' | xargs -J % -n1 cp % dest_folder
This will 这将
src_folder
src_folder
中的所有文件 String
(so that the rest remains) String
开头的东西(剩下的就剩下了) cp
command cp
命令
-n1
says to call cp
for each of them separately) -n1
分别为每个文件调用cp
) % dest_folder
, where %
is replaced by the actual file name. % dest_folder
作为参数,其中%
由实际文件名替换。 cp src_folder/!(String*) dest_folder
试试吧〜克里斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.