LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why can't I copy a directory without using -R ? (https://www.linuxquestions.org/questions/linux-newbie-8/why-cant-i-copy-a-directory-without-using-r-810148/)

Muthu I 05-26-2010 02: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 02:04 AM

Hi,

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 05:08 AM

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

MTK358 05-26-2010 07: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 04:30 PM.