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?
cp omitting directory error solution cp: omitting directory error tells that directories are not copied as the cp command by default works on the files only. Simply, use the cp command with -r or -R (recursive) as an argument to resolve cp: omitting directory error.
You use the cp command for copying files from one location to another. This command can also copy directories (folders). [file/directory-sources] specifies the sources of the files or directories you want to copy. And the [destination] argument specifies the location you want to copy the file to.
In the general case, rsync is definitively slower than a “random copy” (which I assume to be just cp ). This is simply because rsync has to do more work than cp in the general case: Read source files to build list of hashes. Read destination files to build list of hashes.
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:
2>&1
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With