I know with a -f cp should be silent but it's not! I do
cp -rf Functional Functionalssssssss
and if Functional does not exist, it says cannot stat 'Functional'... but I just don't want to see the error message!! I want to handle them myself
I know with a -f cp should be silent but it's not! I do
cp -rf Functional Functionalssssssss
and if Functional does not exist, it says cannot stat 'Functional'... but I just don't want to see the error message!! I want to handle them myself
The cannot stat... output is actually being send to stderr, not stdout. For the specific example you provide in the question, the following will suppress the error output by redirecting stderr to /dev/null:
cp -rf Functional Functionalssssssss 2>/dev/null
As well, at least for the version of cp on my Debian Linux server, -f is not a universal 'silence' flag. It's instead a synonym for --force, meaning that cp will silently obliterate any existing destination file before copying.
If you are using bash or sh(posix standard), [ -f file ] && cp file target
is what you want.
This one will check if the file exists and copy it. Say goodbye to errors.
-r indicating the source may very well be a directory, not a file as tested by [ -f ... ].
– user
May 13 '15 at 14:14
cp. It probably doesn't matter in this case but similar constructs can and have produced catastrophic security holes and other bugs.
– zwol
May 13 '15 at 16:05