0

I have the folder path in LINUX (Ubuntu) as follows:

/data/nldas/raw/hourly/

in the hourly folder I have sub-folders from 1979 to 2016 and in each year folder I have julian day folders from 1 to 365/366. In each julian day folder, I need to copy NLDAS_VIC0125_H.*.grb files to a different destination in LINUX path e.g. /datadg/name/soil. I do not want the same folder structure in the destination path.

Can somebody help me to do in LINUX please?

Thanks in advance.

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.
  • I used the backslash to show that the command was continued after the line break. Either remove the backslash or break the line after the backslash, or see my revised answer – waltinator Jul 11 '17 at 15:48

1 Answers1

1

Read, and re-read man find. Read, and re-read man xargs find and xargs are the answer:

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

Note if there are two NLDAS_VIC0125_H.*.grb files with the SAME name (the '*' is the same in both cases), one will be overwritten in the target directory, unless you use the --backup=numbered option to cp.

waltinator
  • 36,399