476

I've issued the following command:

sudo cp ~/Transfers/ZendFramework-1.11.4-minimal/library/Zend/* ~/public_html/cmsk.dev/library/

When I do this, I start getting the following messages:

cp: omitting directory `Tag' 
cp: omitting directory `Test' 
cp: omitting directory `Text' 
cp: omitting directory `TimeSync' 
cp: omitting directory `Tool' 
cp: omitting directory `Translate' 
cp: omitting directory `Uri' 
cp: omitting directory `Validate' 

and so on...

Why do I get these messages ?

zahypeti
  • 317
MEM
  • 11,065

7 Answers7

629

By default, cp copies only the direct files in, and not subdirectories in the directory. The message cp: omitting directory 'directory' warns you that the mentioned directory is not copied.

To do so, specify the -r (or --recursive) option:

sudo cp -r ~/Transfers/ZendFramework-1.11.4-minimal/library/Zend/* ~/public_html/cmsk.dev/library/

The manual page (command: man cp) contains an overview of the available options.

tony gil
  • 283
Lekensteyn
  • 174,277
  • 2
    Thanks a lot. I thought that * will deal with it recursively somehow. But no. :D Thanks again. :) – MEM Apr 18 '11 at 15:20
  • 12
    @MEM: the * is expanded by Bash, not by cp. Test it yourself by putting echo in front of your command. When expanded, it matches everything with a preceding ...library/Zend/ (the files and directories in it). – Lekensteyn Apr 18 '11 at 15:26
  • 1
    Good news is that omitting directory 'directory' doesn't mean that it is deleting that directory. – Bishwas Mishra Feb 14 '18 at 08:43
  • @Lekensteyn i was trying to copy contents of one user to another .so i gained permission from user with chmod a+rx ~/ after i tried to copy with cp /home/2110/* /home/2111/ it produces error which states permission denied . where i was wrong . sorry to comment because i cant ask duplicate questions. i hope for quick reply :) – jasinth premkumar Feb 16 '18 at 13:58
  • @jasinthpremkumar Files in /home/2110 are owned by user 2110 while files in /home/2111 are supposed to be owned by 2111. To set the owner, use something like sudo chown -R 2111 /home/2111. – Lekensteyn Feb 16 '18 at 15:42
  • Note: cp accepts either -r or -R - I usually use -R for recursive because there are some commands that only accept -R for recursive. – thomasrutter Aug 15 '19 at 03:25
43

The message means that cp hasn't copied the directories listed. This is the default behaviour for cp - only files are copied normally, regardless of if you are specifying them explicitely or using *. If you want directories copying use the -r switch which means "recursive".

Roger Light
  • 1,384
16

Couple of things here which need to check:

  1. Don't use sudo. You don't need it, you already have the permissions to write stuff in your own home directory.

  2. You can easily view hidden files and directories in the graphical file manager by selecting View/Show Hidden Files from the menu. Or by pressing Ctrl - H.

  3. You need to use the -R option in the cp command to copy a directory and it's contents.

  4. /home isn't your home directory. /home/username is. So you are probably trying to copy from wrong place.

  5. The shell is case sensitive, so ~/downloads and ~/Downloads are two different things.

Nikunj K.
  • 261
2

When you are copying a directory like:

cp dir1 copy_of_dir1

You're only and exactly copying the dir1 itself and not the files within it, so at the end you will end up with a new directory structure while the structure does not exist.

In other words after it has been copied it will say that my contents is file1, file2, etc; However these files has not been copied and thus does not exist in it.

So to fix this issue that may came up cp by default does not copy the directories and skips them unless you specify -r option which copies all the files recursively too.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
1

The reason it says omitting directory is because cp and all copy utilities, that I know of, create a list of files and sub-directories to be copied before starting to copy the files. When the --recursive options is missing, sub-directories get bumped off this list. As such, omitting refers to removal from the copy list, not from your source media. I believe this addresses the meaning of the message.

endrias
  • 597
0

The cp command is used to copy files and directory, not the nested directories, if you want to copy nesting directories then you can add -r after that, where -r means recursive.

Syntax that you can follow (running as root):

cp -r /source/dir/* /destination/ 

or

cp --recursive /source/dir/* /destination/
-1

Suppose you have two directories 'Tag' & 'Test'

If you want to copy 'Tag' directory to 'Test' directory use command

$ : cp -r Tag Test (case sensitive)

Mostly Problem will be solved with above code if not and you get below message like

cp: omitting directory `Tag' 
cp: omitting directory `Test'

then add some files in 'Tag' directory and then copy those to 'Test' . Actually i to have same problem but solved like what i said secondly.