LinuxQuestions.org
Help answer threads with 0 replies.
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, 02: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, 02:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 05:08 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

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

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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 07: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 04:19 PM
How to copy files after search in array from this directory to another directory! phanvinhgiap Programming 4 01-04-2009 06:48 PM
Copy directory execlude directory linux2man Linux - General 3 12-12-2006 07:52 AM
How to copy one directory to another directory thru PHP? green_njk Programming 1 01-06-2006 06:55 AM
copy files from directory to directory without subfile ALInux Linux - General 2 06-03-2005 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 PM.

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
Open Source Consulting | Domain Registration