0

I want to copy all files that begin with a string to a folder in the same directory. I've tried cp foo* backup/foo* but get

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
   cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory

How can I copy accomplish this?

3
  • Out of curiosity, why do you use the words "folder" and "directory"? Is there a difference between the two? (I ask this as a person with a great dislike for the word "folder") May 8, 2012 at 0:52
  • I started programming in earnest less than 6 months ago, so a carryover from my days with Finder, I suppose. Folders hold things and directories contain lists of things. Both conceptually make sense, but for different reasons. The latter is better(more accurate) because symlinks don't make sense with the folder analogy.
    – Chris
    May 8, 2012 at 0:57
  • Folder tends to be the term used in GUI, windows-oriented (small w, not the MS big-W) contexts for what's called a directory in the lower-level C APIs and Unix command line contexts. It is perhaps best to be consistent, but I don't think that there'd be a big problem if you'd used folder twice, and obviously not if you'd used directory twice. Elegant variation is more treasured over in EL&U than on StackOverflow. May 8, 2012 at 3:16

1 Answer 1

6
cp foo* backup/

Just specify the target directory. This isn't a DOS command window.

3
  • You are my saviour, thank you. I will accept the answer as soon as SO lets me :)
    – Chris
    May 8, 2012 at 0:46
  • DOS requires that you put the glob in the target argument as well?
    – jordanm
    May 8, 2012 at 2:37
  • 1
    @jordanm: I'm not certain, but it has a certain DOS-like quality. I seem to remember PIP, COPY and things like that doing copying and renaming with things like COPY *.EXE *.BAT (which is a nonsensical operation, but humour me; it's late-ish). OTOH, I make zero claims to have been an expert in DOS and CMD.EXE syntax, even back in the day when DOS was current, let alone after 20+ years of studious neglect of whatever limited knowledge I once had. May 8, 2012 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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