Question

Im trying to find a set number of files in a directory and then copy them to another directory using the find and cp command.

this is the command i have so far:

find /usr/share -name a* -type f -group admin -size -10240c | cp /usr/share/ ./thecopy/

Now it finds the files but does not copy the files to the location I'm trying to send them but finds the files in question. Any suggestions please?

No correct solution

OTHER TIPS

find /usr/share -name a* -type f -group admin -size -10240c -exec cp {} ./thecopy/\;

That won't recreate any directory structure under thecopy. But will copy the files it finds to your directory needed

Try something like:

find /usr/share -name a* -type f -group admin -size -10240c | cp {} ./thecopy/ \;

{} is the placeholder for the files that match your criteria

If you want to retain the directory structure you can try something like:

find /usr/share -name a* -type f -group admin -size -10240c | rsync -av {} ./thecopy/ \;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top