在 Ubuntu 中将多个文件夹中选定的文件复制到不同的目标

在 Ubuntu 中将多个文件夹中选定的文件复制到不同的目标

我在LINUX(Ubuntu)中的文件夹路径如下:

/data/nldas/raw/hourly/

在小时文件夹中,我有从 1979 到 2016 的子文件夹,在每个年份文件夹中,我有从 1 到 365/366 的儒略日文件夹。在每个儒略日文件夹中,我需要将NLDAS_VIC0125_H.*.grb文件复制到 LINUX 路径中的不同目标,例如/datadg/name/soil。我不希望目标路径中的文件夹结构相同。

有人可以在 LINUX 上帮我做吗?

提前致谢。

Error:

\name@lin-v01:/$ find /datadg/RND_Data/ldas/raw/hourly/ -type f -name 'NLDAS_VIC0125_H.*.grb \ -print0 | xargs -0 cp --target-directory=/datadg/rndFS/name/soilM
find /datadg/RND_Data/ldas/raw/hourly/ -type f -name 'NLDAS_VIC0125_H.*.grb \ -print | xargs -0 cp --target-directory=/datadg/rndFS/name/soilM
find: warning: Unix filenames usually don't contain slashes (though pathnames do).  That means that '-name `NLDAS_VIC0125_H.*.grb \\ -print | xargs -0 cp --target-directory=/datadg/rndFS/name/soilM\nfind /datadg/RND_Data/ldas/raw/hourly/ -type f -name NLDAS_VIC0125_H.*.grb'' will probably evaluate to false all the time on this system.  You might find the '-wholename' test more useful, or perhaps '-samefile'.  Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `NLDAS_VIC0125_H.*.grb \\ -print | xargs -0 cp --target-directory=/datadg/rndFS/name/soilM\nfind /datadg/RND_Data/ldas/raw/hourly/ -type f -name NLDAS_VIC0125_H.*.grb''.
find: paths must precede expression:  -print
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
cp: missing file operand
Try `cp --help' for more information.

答案1

阅读,再阅读man find。 阅读,再阅读man xargs findxargs答案如下:

find /data/nldas/raw/hourly/ -type f -name 'NLDAS_VIC0125_H.*.grb' -print0 | xargs -0 cp --target-directory=/datag/name/soil

请注意,如果有两个NLDAS_VIC0125_H.*.grb文件具有相同的名称(两个情况下的“*”相同),则目标目录中的一个将被覆盖,除非您使用--backup=numbered选项cp

相关内容