Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-29-2008, 02:28 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 1

Rep: Reputation: 0
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?

Old 08-29-2008, 02:31 AM   #2
Registered: Mar 2007
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 166

Rep: Reputation: 74
$ 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
Old 08-29-2008, 04:10 AM   #3
Registered: Aug 2007
Distribution: openSUSE 12.1
Posts: 98

Rep: Reputation: 24
the '-f' option for cp has the follwing meaning:
-f, --force
if an existing destination file cannot be opened, remove it and try again
and there's no switch what to do if the source does not exist, so you have to use the solution rocket357 priveded...
Old 08-29-2008, 10:02 AM   #4
Registered: Mar 2007
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 166

Rep: Reputation: 74
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 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).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
upsmon ignoring &> Red Squirrel Linux - Software 3 08-01-2006 05:11 PM
Ignoring difference of { and } anandss2004 Programming 7 11-01-2005 08:11 PM
ignoring dependencies ergo_sum Linux - Newbie 1 04-03-2005 07:05 PM
ignoring drive Y: Johng Linux - Software 2 12-14-2003 03:09 PM
up2date is ignoring me nattybumpo Linux - Networking 1 04-24-2003 02:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration