cp: silence "omitting directory" warning

11,104

Solution 1

Probably you want to use cp -r in that script. That would copy the source recursively including directories. Directories will get copied and the messages will disappear.


If you don't want to copy directories you can do the following:

  • redirect stderr to stdout using 2>&1
  • pipe the output to grep -v
script 2>&1 | grep -v 'omitting directory' 

quote from grep man page:

  -v, --invert-match
          Invert the sense of matching, to select non-matching lines.

Solution 2

The solution that works for me is the following:

find -maxdepth 1 -type f -exec cp {} backup_1364935268/ \;

It copies all (including these starting with a dot) files from the current directory, does not touch directories and does not complain about it.

Share:
11,104
Ajedi32
Author by

Ajedi32

Full stack web developer/Linux admin/DevOps guy with experience in a broad range of topics including Ruby on Rails, Docker, Bash, JavaScript, PowerShell, git, etc.

Updated on June 22, 2022

Comments

  • Ajedi32
    Ajedi32 about 2 years

    I'm using the command cp ./* "backup_$timestamp" in a bash script to backup all files in directory into a backup folder in a subdirectory. This works fine, but the script keeps outputting warning messages:

    cp: omitting directory `./backup_1364935268'
    

    How do I tell cp to shut up without silencing any other warnings that I might want to know about?