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 Console Foundations Getting Started with the Console Moving and Deleting Files

What is -r in the command cp -r in the console?

I don't quite get the -r after the command in the console, I know it' something about "recursive", but what is recursive and why we cannot copy directories without using -r?

1 Answer

Adam Sommer
Adam Sommer
62,470 Points

You're right the -r is recursive meaning that if the file is a directory it will copy it and all it's contents and subdirectories.

Recursive is a fancy word for this and everything below. If you think of a directory structure as an upside down tree you have the root and branches going down. Recursiveness follows all the little branches to their end.

As to why you can't copy directories without the -r, I guess because back in the day they thought it'd be more useful to have a utility to just copy files and if you needed to copy whole directories you should add a switch to the command.

This article might explain things better than I can.

Thanks for answer, the link you provided is helpful too.

the same doesn't apply to moving a directory...i.e you don't need the -r switch. Do you know the rationale for that?