Cp: ​​warning about "disable directory"

I use the cp ./* "backup_$timestamp" command in a bash script to backup all files in a directory to a backup folder in a subdirectory. This works fine, but the script continues to display warning messages:

 cp: omitting directory `./backup_1364935268' 

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

+6
source share
2 answers

Perhaps you want to use cp -r in this script. This will copy the source recursively, including directories. Directories will be copied and messages will disappear.


If you do not want to copy directories, you can do the following:

  • redirect stderr to stdout with 2>&1
  • prints output to grep -v
 script | grep -v 'omitting directory' 

quote from grep man page:

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

The solution that works for me is the following:

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

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

+7
source

All Articles