How to copy all the content of a directory in Unix without “cp: omitting directory” error [Quick Tip]

Share this article

Problem Scenario:

You want to copy all the contents of a directory (lets say source_dir) which contains lots of other files and subdirectories inside it to another directory (lets say target_dir). If you simply try cp command it may result in the following error:

command: cp source_dir target_dir
output: cp: omitting directory source_dir

If you try recursive copy (using option -r) the directory is copied inside the target directory which you may not be suitable if you want to duplicate the contents of the source directory.

command: cp -r source_dir target_dir
command: ls target_dir
output: source_dir

Solution:

If you want to copy just the contents of the source directory as in duplicating all its contents use the following command:

command: cp -r source_dir/* target_dir

This command will copy all the content (not the directory itself) in the target directory.