What is cp: omitting directory error in Linux and how to solve

cp omitting error in Linux

Linux cp command allows you to copy files and directories. By default, it works on file only. When you try to copy a directory, you get the cp: -r not specified; omitting directory error on the terminal.

Let’s reproduce the error.

Copy a file from src_file.txt to /home/imaginelinux/dest_dir folder.

cp src_file.txt /home/imaginelinux/dest_dir

This works fine for files.

Now, let’s run the command for the directory and see what happens. Copy a directory from src_dir to desk_dir.

cp src_dir desk_dir
cp: -r not specified; omitting directory 'src_dir'

What is wrong with the copy command? Why is the error message cp omitting directory?

cp omitting directory error solution

cp: omitting directory error tells that directories are not copied as the cp command by default works on the files only. Simply, use the cp command with  -r or -R (recursive) as an argument to resolve cp: omitting directory error.

 -R, -r, --recursive
copy directories recursively

The cp command – r or -R (recursive) option, allows you to copy directories/subdirectories recursively.

Now let’s again run the copy command now with the – r option.

cp -r src_dir dest_dir

or

cp -R src_dir dest_dir

Now you can see the command worked fine and directories along with contents are also copied.

Summary

In conclusion, the “cp: omitting directory” error in Linux arises when you attempt to use the ‘cp’ command to copy a directory without the appropriate options. By default, the ‘cp’ command is designed for copying files, not directories.

The solution to this issue is to use the ‘-R’ or ‘-r’ option, which stands for ‘recursive’, to ensure the directory and its contents are copied successfully.

Refer to this discussion on Askubuntu and StackOverflow for additional details.

I hope you found this article helpful. Please share and subscribe.

What this video tutorial:

Scroll to Top