Latest LQ Deal: Linux Power User Bundle
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 09-20-2004, 04:33 AM   #1
Registered: Jul 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, 05:06 AM   #2
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, 05:10 AM   #3
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
/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
man bash
for much more detail.


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 01:46 PM
mv c:\WINDOWS /dev/null; mount /dev/hda treehead Member Intro 5 10-19-2004 09:53 AM
Creating a printer, but sending to a script & /dev/null, how to? cougar694u Linux - Software 1 09-24-2004 02:38 PM
2>/dev/null && {...} need explanation G-Fox Linux - Networking 2 08-16-2003 01:31 PM
> /dev/null 2>&1 Sammy2ooo Linux - Software 2 07-16-2003 10:20 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:49 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