I have an image folder which I am trying to copy into a subfolder of itself, so I can resize the images there.

It looks something like this:

Sephs-MacBook-Pro:photos seph$ ls
100x100                                 image1.png
image2.png                              image3.png
image4.png                              pic1.jpg

The issue I have is when I run the function Sephs-MacBook-Pro:photos seph$ cp -R ./. 100x100 I get an error, which basically says I can't keep adding 100x100 folders to themselves:

cp: 100x100/./100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/.DS_Store: name too long (not copied)

How do I use cp -R to copy files to a subfolder without also copying the subfolder?


Using cp ./*.* ./100x100 without the -R option will copy all files in the directory into the 100x100 subdirectory without copying the directory into itself.

The -R option is for recursively copying all subdirectories into the target and should not be used if you do not want that to happen.

See man cp for more information on the options for the command and what they do.

  • cp ./*.* ./100x100 without the -R option will copy all files with a dot in the filename... If you meant what you wrote you would use cp ./* 100x100 – roaima Dec 31 '17 at 9:05
  • All image files with a type extension have a dot in the filename, while directories (and other, possibly broken, files) do not. That's why it works. ;) – Mio Rin Dec 31 '17 at 10:07
  • My point is that *.* does not match all files, as you have written. – roaima Dec 31 '17 at 15:19
  • This wouldn't copy other directories either. – jdwolf Dec 31 '17 at 17:32

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.