-   Linux - Newbie (
-   -   why can't I copy a directory without using -R ? (

Muthu I 05-26-2010 03:02 AM

why can't I copy a directory without using -R ?
why can't I copy a directory without using -R ? It shows "cp: omitting directory" .

druuna 05-26-2010 03:04 AM


cp is meant (without any options) to only work on the current working directory and _not_ on any subdirectories (with or without files). As stated in the man page, you need to use -R to copy recursively.

This is the way it is implemented.

Hope this helps.

syg00 05-26-2010 06:08 AM

You can.
If you don't agree with the implementation, write your own.

MTK358 05-26-2010 08:04 AM

Because in Linux, directories don't actually contain files. They contain a list of "addresses" to files. So just directly copying the directory wouldn't copy the files inside.

The -R option tells cp that when it comes across a directory, it should create a new directory in the destination, and start copying files from the subdirectory.

But personally, I think it's really stupid that cp doesn't recursively copy dirs by default, as if that's not what you always need and expect.

All times are GMT -5. The time now is 09:45 PM.