LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2010, 03:02 AM   #1
Muthu I
LQ Newbie
 
Registered: May 2010
Location: India
Distribution: Fedora
Posts: 14

Rep: Reputation: 1
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" .
 
Old 05-26-2010, 03:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 05-26-2010, 06:08 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,834

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
You can.
If you don't agree with the implementation, write your own.
 
Old 05-26-2010, 08:04 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
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.

Last edited by MTK358; 05-26-2010 at 08:06 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Copy files from local directory to a particular directory using alias dynamics Linux - Newbie 7 09-11-2009 05:19 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 07:48 PM
Copy directory execlude directory linux2man Linux - General 3 12-12-2006 08:52 AM
How to copy one directory to another directory thru PHP? green_njk Programming 1 01-06-2006 07:55 AM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 12:51 PM


All times are GMT -5. The time now is 04:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration