1
cp -v /var/www /var/www/dev
cp -vR /var/www/admin /var/www/dev
cp -vR /var/www/cron /var/www/dev
cp -vR /var/www/css /var/www/dev
cp -vR /var/www/files /var/www/dev
cp -vR /var/www/images /var/www/dev
cp -vR /var/www/js /var/www/dev
cp -vR /var/www/medlem /var/www/dev
cp -vR /var/www/snippets /var/www/dev

It is only the first one that doesn't copy the files. I know this is far from the best solution but yeah, it works kinda well a part from the first cp not copying. Every cp except the first one works. I want the first one to only copy files and not go into directories and copy. I just get the error

cp: omitting directory '/var/www'

2 Answers 2

7

By default, cp will not copy directories. This protects you from accidentally copying too much.

$ cp -v /var/www /var/www/dev
cp: omitting directory `/var/www'

To override this default, supply the -R option:

$ cp -vR /var/www /var/www/dev
`/var/www' -> `/var/www/dev/www'

The reason that this was the only command that failed was that this was the only command that was missing -R.

0
0

John1024's answer, does answer the question, however, I would argue that the reasoning is not wholly accurate. It is correct that, by default, the cp command will not copy directories, however the implication that this is primarily to protect the user from "copying too much" seems unlikely.

Ubuntu operates a Unix-style file system, which uses the concept of inodes to describe a filesystem object, be it a file or a directory.

A directory is simply a list of names assigned to inodes. In that sense, the visual representation provided by the GUI is somewhat of an illusion, i.e. a directory is not actually a 'container' of other files, but rather a list of file names and inode pointers.

.....a directory entry contains only a name for the associated file and a pointer 
to the file itself. This pointer is an integer called the i-number (for index 
number) of the file. When the file is accessed, its i-number is used as an index 
into a system table (the i-list) stored in a known part of the device on which the 
directory resides. The entry found thereby (the file's i-node) contains the 
description of the file:...
   — The UNIX Time-Sharing System, The Bell System Technical Journal, 1978

From this perspective, we can see that copying a directory, would simply copy a list of names and associated inodes; this would be akin to creating a hard link to the directory. This is (probably) not the user's actual intention when copying a directory. In all likelihood, when copying a directory using the cp command, a user intends to make a physical copy of the actual data files within.

Therefore, I would argue that using the -r option when copying directories, makes the command explicit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .