I'm taking a basic Unix course and right now we're learning terminal. My directions are create a directory called company and subdirectories called sales, accounting and marketing. So I did that.

mkdir company
cd company
mkdir sales
mkdir accounting
mkdir marketing

And then create files called file1, file2 and file3 inside company.

touch file1
touch file2
touch file3

And then copy file 1 2 and 3 to the 3 subdirectories I have created but I'm stuck on copying it to the first directory.

cp company/file1 company/file2 company/file3 company/sales

But the terminal prints an error, "cp: target 'company/sales' is not a directory." How is this the case when I just made a directory called sales, and when I ls inside of company it lists the sales folder?

cd company
accounting file1 file2 file3 marketing sales
  • 2
    What is your pwd when you run that cp command? – goldilocks Feb 21 '15 at 11:59

If you are in the company directory then try this:

cp file1 sales
cp file2 sales


cp file1 sales; cp file2 sales


cp file1 file2 file3 sales

The last is the easiest and can accomplish copying all files it a single subdirectory in one line. If you want to complete the task and copy each file to each subdirectory in one line, merge the second and third example like this:

cp file1 file2 file3 sales; cp file1 file2 file3 accounting; cp file1 file2 file3 marketing

One last example is this:

for d in */; do cp file* "$d"; done

The file* is locating every thing within the current directory that starts with "file" and copies it to every first-level subdirectory.

  • Thank you! I didn't know it mattered that I was already in the company directory but that fixed it. And thanks for the easy way to do it. – joe32 Feb 21 '15 at 12:11
  • @joe32 Anytime and glad to help. If this answered your question, feel free to mark it as the accepted answer. – les Feb 21 '15 at 12:19

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.