Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

sean chan
sean chan
2,092 Points

use cp on existing directory behave differently

If I type "cp -r documents docs", a new docs directory is created under current directory. However if I use "mkdir docs" to create docs directory first, then use the "cp -r documents docs" command, the whole documents is copied into the docs(e.g. docs/documents). Is this the normal behavior? I am expecting only the content(how_to_go_home.txt) of documents being copied to docs. How can I copy the content only to an existing directory?

1 Answer

akak
akak
29,445 Points

Yes, it's normal :)

To copy all contents of a directory to another directory use:

cp documents/* docs