LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-17-2007, 04:10 PM   #1
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Rep: Reputation: 31
/dev/null 2>&1 ???????????


i know that /dev/null is used redirect output of commands in shell scripts to a null device so the user won't see a lot of output when running certain scripts.
here is my question: what is the difference between these two command?
Code:
ls -l /etc | grep resolv.conf > /dev/null
and
Code:
ls -l /etc/ | grep resolv.conf > /dev/null 2>&1
i just want to understand what 2>&1 means.
 
Old 05-17-2007, 04:23 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
> redirects the stdout stream, same as 1> as 1 is the number of that stream. 2 is the stderr stream. 2>&1 causes stderr to be redirected into stdout and then sunk into /dev/null, otherwise whilst all normal output disappears, any errors (e.g ls command not found, resolv.conf not allowd to be opened) would still show up. in the longest form you could write....

ls -l /etc/ | grep resolv.conf 1> /dev/null 2> /dev/null

but oviosuly, that's longer hence shortcuts and such.
 
Old 05-17-2007, 10:22 PM   #3
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Original Poster
Rep: Reputation: 31
after reading your reply and http://en.wikipedia.org/wiki/Redirection_%28Unix%29 i understand now why it's very commonly used. Otherwise, a lot of scripts will show a whole load of errors.
thanks.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 10:51 PM
Creating a printer, but sending to a script & /dev/null, how to? cougar694u Linux - Software 1 09-24-2004 01:38 PM
> /dev/null 2>&1 blackzone Linux - Newbie 2 09-20-2004 04:10 AM
2>/dev/null && {...} need explanation G-Fox Linux - Networking 2 08-16-2003 12:31 PM
> /dev/null 2>&1 Sammy2ooo Linux - Software 2 07-16-2003 09:20 AM


All times are GMT -5. The time now is 02:37 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration