Ignoring cp errors.
With rm using the -f flag will ignore any errors, e.g.
rm -f test
won't display an error message if test does not exist. However cp doesn't seem to have a similar option. The -f in cp seems to work differently. Is there a way to have cp hide or ignore error message?
$ cp thisFileDoesntExist hello_world
cp: thisFileDoesntExist: No such file or directory
to remove the error, just redirect stderr to /dev/null:
$ cp thisFileDoesntExist hello_world 2>/dev/null
the '-f' option for cp has the follwing meaning:
To post a quick follow-up, there are three "file descriptors" you need to get to know: stdin(0), stdout(1), stderr(2). There's all kinds of nifty things you can do with stdout and stderr...you just have to give the file descriptor *number* (2 in my above post for "stderr").
The beauty of using 2>/dev/null (send all data on stderr to the bit bucket) is that it works with ANY command without touching the "normal" stdout data.
You can also combine stdout and stderr like such:
$ some_command >/dev/null 2>&1 # ">/dev/null" assumes stdout, "2>&1" redirects stderr to stdout (and hence, to /dev/null in this example).
|All times are GMT -5. The time now is 08:07 AM.|