2

Hey, not 100% sure what this error means.

% for f in "*" ; do cp $f ../backup/backup$f ; done
cp: ../backup/backup* not found

The purpose is to copy all the files into a folder into a backup folder and rename the files to backup.

sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213

3 Answers3

10

The * shouldn't be in quotes:

for f in * ; do cp $f ../backup/$f ; done

When you use quotes this prevents the shell from expanding it, so it is looking for a file called *, not all files in the directory which is what you meant.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
7

You are quoting the wrong things: quote the variables, not the wildcards!

% for f in *; do cp "$f" "../backup/$f" ; done

BTW, in this case, you can simply do:

% cp * ../backup/

janmoesen
  • 7,910
  • 1
  • 23
  • 19
3

Or may be this:

cp -b * ../backup 

If you want them to be renamed:

% for f in * ; do cp "$f" "../backup/${f}-backup" ; done
sud03r
  • 19,109
  • 16
  • 77
  • 96