cp: omitting directory – error while copying a directory in Linux

The Problem

When we are trying to copy a directory to other location, we get below error:

$ cp /data01 /data02
cp: omitting directory '/data01'
$

The Solution

The error above is a common mistake done by Linux newbies while copying a directory to other locations without using the recursive copy option in the ‘cp’ command.

In order to avoid this error use the “-r” or the “-a” option in the copy command. From the man page of ‘cp’ command:

# man cp
-R, -r, --recursive
    copy directories recursively

-a, --archive
    same as -dR --preserve=all

For example:

# cp -r /srcdir /tgtdir

or

# cp -R /srcdir /tgtdir

or

# cp -a /srcdir /tgtdir

If you do not use the “-r” or “-a” options in cp command, by default the command will try to only copy the files and not the directories from the source. The “-r” and “-R” are the same options and can be used interchangeably.

Related Post