0

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:

$ ls
100x100                                 image1.png
image2.png                              image3.png
image4.png                              pic1.jpg

The issue I have is when I run the command 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?

αғsнιη
  • 41,407
Seph Reed
  • 203

2 Answers2

2

If your shell is zsh (likely if you're on macos):

set -o extendedglob # best in ~/.zshrc
cp -- {^,}100x100

Would expand to:

cp -- ^100x100 100x100

That is, copy all files but 100x100 into 100x100.

To also copy hidden files:

cp -- ^100x100(D) 100x100

To only copy regular files (nor directories, symlinks, etc):

cp -- ^100x100(D.) 100x100
1

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.

Mio Rin
  • 3,040