-1

I have used photorec to recover data from a HDD and now have many directories /home/ray/recup_dir.1, to /home/ray/recup-dir.598 taking up valuable space in my Home directory.

I want to copy them into another directory /media/ray/"Seagate Expansion Drive"/RecupsA

How do I do this with one command?

  • 4
    What is wrong with cp? Like cp -r /home/ray/recup_dir.{1..598} "/media/ray/Seagate Expansion Drive"/RecupsA". Or maybe you want rather to move them, not copy? – jimmij Jan 3 '15 at 11:47
2

The first solution I thought of is rsync. Exclude everything. Include directories matching a pattern. I'll admit that it feels strange to copy information to the same host using rsync. Usually it it used to copy to a remote computer. However I see no reason why you could not just copy to localhost.

rsync -ravz --include '/home/ray/recup_dir.*' --exclude '*' user@localhost

Explanation of ravz:

-r recursive copy
-v verbose
-a : archive mode. Preserves symbolic links, file permissions, user & group ownerships,  timestamps
-z : compress file data


A second option is to cheat and type mc. This will start midnight commander, allowing you to select multiple directories and then copy them.


Third option: find.

find /home/ray/recup_dir.\*  -exec cp {} /media/ray/"Seagate Expansion Drive"/RecupsA \;


Fourth option: Use the shell. Go to /home/ray/ and then

for a in recup* ; do cp -r $a /media/ray/"Seagate Expansion Drive"/RecupsA; done
2

Use standard cp with recursive option:

cp -r /home/ray/recup_dir.{1..598} "/media/ray/Seagate Expansion Drive/RecupsA"

But I have a feeling that you rather want to move them, in such case:

mv /home/ray/recup_dir.{1..598} "/media/ray/Seagate Expansion Drive/RecupsA"

Both those commands treat only last argument as destination, and all previous ones as sources (files or directories).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.