LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-29-2008, 01:28 AM   #1
0boolean1
LQ Newbie
 
Registered: Aug 2008
Posts: 1

Rep: Reputation: 0
Ignoring cp errors.


Hello

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?

Thanks
 
Old 08-29-2008, 01:31 AM   #2
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 187

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, 03:10 AM   #3
JSkywalker
Member
 
Registered: Aug 2007
Distribution: openSUSE
Posts: 102

Rep: Reputation: 24
the '-f' option for cp has the follwing meaning:
Quote:
-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, 09:02 AM   #4
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 187

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 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).
 
  


Reply



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 04:11 PM
Ignoring difference of { and } anandss2004 Programming 7 11-01-2005 07:11 PM
ignoring dependencies ergo_sum Linux - Newbie 1 04-03-2005 06:05 PM
ignoring drive Y: Johng Linux - Software 2 12-14-2003 02:09 PM
up2date is ignoring me nattybumpo Linux - Networking 1 04-24-2003 01:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:56 PM.

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