Skip to content
Advertisement

Newbie-ish error: cp: omitting directory

Pulling my hair as I’m stuck with a basic error without understanding why:

find . -type f -exec cp del {} ;

We’re in a “test” directory, in which I created one “del” subdirectory. The “test” directory contains a variety of files of various types.

The result is a series of lines (same number as the number of files present in the directory from where the command is ran) with:

cp: omitting directory `del'

Possibly useful details follow.

  • Debian Wheezy, standard shell interface.
  • As a prelude to more complex exclusion and exec patterns I wanted to start with this fundamental test… and had this.
  • I think I excluded the “del” directory with “type -f”, so it’s not as if I was asking Linux to move a directory within itself.
  • There are no other directories or subdirectories.
  • Permissions: everything belongs to the current user.
  • I made variations for the “cp del” part, putting it in simple or double quotes, or using ./del, no difference.

I also tried with -R

find . -type f -name '*script1*' -exec cp -R ./del {} ;

That gave:

cp: cannot overwrite non-directory `./script1' with directory `./del'

Same with -r

Advertisement

Answer

If what you’re trying to do is to copy some files found by find command to the del directory, then you can do it like this:

find . -type f | xargs cp -T del/

Or like this:

find . -type f -exec cp {} del ;
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement