It won't look like it, but I've spent 3+ hours trying to figure this out... I am trying to identify files in all subdirectories of a parent directory with particular attributes (name and size) then rename the files to their subdirectory name and copy them to the parent directory. My closest attempt (I think) has been:
find /data/data2/parent/ -size 25166176c -name "o*.nii" -exec cp {} $subdir/o*.nii $subdir.nii \;
To this, I get two lines of: "cp: target '/data/data2/parent/3145_V2.nii' is not a directory" I checked to make sure there is only one file that would meet both attributes, and there is. Also noteworthy, there are two subdirectories under "parent/" with a relevant file that should be picked up by the find command but it only printed the error regarding one of the two, "parent/3145_v2" (and appeared to ignore the other subdirectory).
find
find the correct files, and no more? Does thecp
/mv
command work on its own? A "rename" would be done bymv
, notcp
. And, is it correct that the file should be renamed AND copied? On top,find
might not be able to extract the subdir name, so that would have to be done elsewhere.