LINUX CP:我需要将所有文件从一个目录复制到另一个目录而不复制任何子目录

LINUX CP: I need to copy all files from one directory to another without copying any sub-directories

我需要将文件从一个目录复制到另一个目录而不复制任何子目录。子目录的数量和名称是动态的,所以我不能“--exclude”特定目录或使用“-r”选项。如何排除所有子目录?

代码 1:

cp '/media/lm1/My Passport/OneDrive/Music/Yes/*.*' '/home/lm1/Music/Archive'

结果 1:

p: cannot stat '/media/lm1/My Passport/OneDrive/Music/Yes/*.*': No such file or directory

代码 2:

cp '/media/lm1/My Passport/OneDrive/Music/Yes/*' '/home/lm1/Music/Archive'

结果 2:

p: cannot stat '/media/lm1/My Passport/OneDrive/Music/Yes/*': No such file or directory

代码 3:

cp '/media/lm1/My Passport/OneDrive/Music/Yes' '/home/lm1/Music/Archive'

结果 3:

cp: -r not specified; omitting directory '/media/lm1/My Passport/OneDrive/Music/Yes'

全局模式(通配符 *.*)在引号内不起作用,但您可以像这样将全局模式移到引号外:

cp '/media/lm1/My Passport/OneDrive/Music/Yes/'*.* '/home/lm1/Music/Archive'

试试 cp /media/lm1/My\ Passport/OneDrive/Music/Yes/* /home/lm1/Music/Archive

使用引号停止 shell 扩展,因此转义 space 字符。