Source: youtube.com

I was trying to copy a directory, and I kept getting a cryptic error:

cp: omitting directory `/var/log'

The copy (cp) command only works for files. To copy a directory, you need to use the -r recursive flag:

cp -r /var/log backup/log_dir_backup

In this case, I was trying to copy the log directory to make a quick and dirty backup. This failed with a long list of “cannot open ‘file…’ for reading: Permission denied” errors. Naturally I needed to us sudu:

sudo cp -r /var/log backup/log_dir_backup

Now it worked.

The move mv command works the same way. You need to use the -r recursive flag to mv a directory:

mv -r log_dir_backup log_backup_yyyymmdd