LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 09-20-2004, 03:33 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
> /dev/null 2>&1


saw someone write " > /dev/null 2> &1" after commands

I know > /dev/null send it to a blackhole. But why add 2 > &1.

I remembered it might have to do with standard error or something. What does it mean. and what other arguments do people put /dev/null.
 
Old 09-20-2004, 04:06 AM   #2
sjoe
LQ Newbie
 
Registered: Aug 2004
Distribution: Red Hat 8.0 2.4.20-28.8
Posts: 6

Rep: Reputation: 0
The "2>&1" is NOT an argument to /dev/null!

Just as "> /dev/null" redirect standard output to /dev/null, "2> &1" redirect standard error to the same file as standard output (in this case to /dev/null).

So ">/dev/null 2>&1" is added after commands if you are not interested in the output from the command.
 
Old 09-20-2004, 04:10 AM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
/dev/null is a special file that automatically (and efficiently) deletes whatever is written to it.

The “>” operator tells the shell to take the output (known as the standard output stream) of a command, and save it to the given file.

“2>” is another form of this, and means to take the error messages from the command (the standard error stream) and save it to the given file instead.

“&1” is a special file that means “the standard output”. So “2>&1” means to redirect the standard error stream to the standard output, in this case /dev/null which causes the streams to be deleted.

You can also have other variations like “1>&2”, which would take the standard output and redirect it to standard error.

“2>&1 >” also has the short-hand form “&>”, meaning “merge standard output and standard error and redirect to…”

You can also use “>>” instead of “>” meaning to append to a file instead of deleting it (not useful with /dev/null).

Also, none of the above are actually arguments to the program; they are all interpreted by the shell, meaning that they can be used with any program. See
Code:
man bash
for much more detail.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What would happen if I where to cat /dev/mem > /dev/null Joey.Dale Linux - General 11 07-26-2009 12:46 PM
mv c:\WINDOWS /dev/null; mount /dev/hda treehead LinuxQuestions.org Member Intro 5 10-19-2004 08:53 AM
Creating a printer, but sending to a script & /dev/null, how to? cougar694u Linux - Software 1 09-24-2004 01:38 PM
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 12:18 PM.

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