1

I have rescued many files from a failing hard disk. They are in 500 sub directories each containing 500 files.

I am trying to copy all the files in all the folders into new subject directories (like jpg, mp3 etc)

Inside the top level directory (MikeO) I am using the following command:

cp -R * /test1

where test1 has already been created under MikeO

This just recreates the entire sub-directory structure and all the files in test1

cp -R *.jpg /test1 results in:
cp: cannot stat ‘*.jpg’: No such file or directory

can anyone point me in the right direction?

1

There are no files named ".jpg" in the location where you issued the command. You need to take that literal: ".jpg" is NOT ".JPG" or ".jPg" or any other combination. Windows is different in that way: it will see those as the same.

In the same directory do an ls and it will show contents of that directory. ls *jpg to list all files ending on *.jpg.

Mind that -R means recursive BUT that applies to directories only when copy-ing. It does not mean it will get you all files in all directories that have a file ending in *.jpg.

If you want to find all files ending in *.jpg and copy them over to /test1/ this will work:

find . -depth -name '*.jpg' -print | cpio -pmdv /test1/

Add a ~ to /test1/ if it is in your home directory.

where test1 has already been created under MikeO

What do you mean with this? If you meand "MikeO" home directory: the / starts at / (ie. root). If you meand /home/MikeO/test/ you need a ~ in front of the /test1.

  • cpio: cannot make directory `/test1': Permission denied cpio: /test1//./recup_dir.1/recup_dir.140/f14847120.jpg: Function open failed: No such file or directory ^C tony@tony-HP-620:/media/tony/Seagate Backup Plus Drive/MikeO$ ^C – TonyC Dec 6 '14 at 12:52
  • Thanks Rinzwind. I liked your complex code - but it doesn't work even when executed with "sudo" in front. Your other comment about .jpg I understand. FYI MikeO is a directory on an external USB hdd – TonyC Dec 6 '14 at 12:56
  • @TonyC that 1st one: test with sudo. might be permissions problem if you do not own the disk ;) – Rinzwind Dec 6 '14 at 13:46
  • I can now get the first part of your code snippet to work. Up to the -print statement I get all the jpg files listed on the screen. Where it falls over is in the cpio command. I checked the syntax which looks fine but as soon as I execute the full command, I get: cpio: cannot make directory `/test1': Permission denied cpio: /test1//./recup_dir.375/f73577640.jpg: Function open failed: No such file or directory – TonyC Dec 6 '14 at 13:50
  • I do own the disk and /test1 exists! – TonyC Dec 6 '14 at 13:51
0

You can use rsync instead of cp command to copy particular extension files. Following is command for copying only .jpg extension files.

rsync -pavr                                                 \
    --include '+ */' --include '*.jpg' --exclude '- *'      \
    /path/to/source/directory  /path/to/destination/directory

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.