Skip to main content

Understanding cp -r not specified, omitting directory Error

Tried copying something in the Ubuntu and it showed "cp: -r not specified; omitting directory" error? Here's why you see it and what you can do about it.


So, you just tried to copy a directory to another location in the Ubuntu command line and it showed you this error.

cp: -r not specified; omitting directory 'dir_name'

I presume that you are new to Linux commands. You know that the cp command can be used to copy both files and folders in the terminal. However, you made the classic 'error' almost every new Linux user makes. You forgot to specify the -r option.

To copy a folder in the command line, you must add the recursive option -r:

cp -r dir_name new_location

The error message hints that "-r was not specified" and hence it is omitting the specified directory from the copying process.

Let's see it a bit in more detail.

cp omitting directory error: reason and solution

The cp command is used for copying files and directories (folders) in Linux.

By default, the cp command only copies the files. To copy a folder from one location to another, you must specify the recursive option -r.

If the copy operation was successful, you wouldn't see any output.

root@learnubuntu:~# cp toto logs
cp: -r not specified; omitting directory 'toto'
root@learnubuntu:~# cp -r toto logs

In fact, it is the same case with the rm command. The rm command removes files, but if you want to remove a folder, you must specify the recursive option -r.

You may also use -R or --recursive options. They are all the same and the result is also the same. However, I suggest using -r as it is more common and you need fewer keystrokes than -R or --recusrive.

The same goes for the remove command, rm. It removes files by default and you need to add -r option if you want to delete folders.

How do you know if it is a file or directory?

Asking the good although a basic question.

You can long list the contents of a directory and observe its output.

ls -l

The entries starting with - are files and the ones starting with d are directories.

The directory entries start with d, files with -

Most of the time, directories are shown in different colors, too. However, that really depends on how your terminal is configured or how you have set up your bash profile.

Time to brush up on the basics

Everyone makes encounters like this in the early days of exploring and using Linux commands. The more you use the commands, the better you get at it eventually.