Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"
# 1  
Old 12-14-2009
Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"

Does >/dev/null 2>&1 and 2>&1 >/dev/null mean the same?
# 2  
Old 12-14-2009
Hi.

They're not the same.

In the first case, standard output is directed to a file (in this case /dev/null), and then standard error is directed to the same place (&1, or /dev/null).

It's equivalent to

Code:
> /dev/null 2> /dev/null

In the second case, standard error is directed to where standard output is directed at the time (i.e. the screen), and then standard output is directed to somewhere else (/dev/null)

Code:
$ cat Test
echo stdout
echo stderr >&2

$ ./Test > /dev/null 2>&1
$

$ ./Test 2>&1 > /dev/null
stderr

# 3  
Old 12-14-2009
Then basically ">/dev/null 2>&1" and "&> /dev/null" do the same job i guess??

Last edited by proactiveaditya; 12-14-2009 at 09:50 AM..
# 4  
Old 12-14-2009
Quote:
Originally Posted by proactiveaditya
Then basically ">/dev/null 2>&1" and "&> /dev/null" do the same job i guess??
Code:
&> /dev/null

Works only in Bash FWIK.
# 5  
Old 12-14-2009
Code:
[root@wiki ~]# echo "1" &> /dev/null
[root@wiki ~]#
[root@wiki ~]# ech "1" &> /dev/null
[root@wiki ~]#

">/dev/null 2>&1" and "&> /dev/null" does the same job
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Web Development

How would I mod_rewrite "/~a1Pha" and "/=a1Pha" to "/paste/a1Pha.htm"? (internally & externally)

Basically I want to shorten URLs on my html pasting site (pasteht.ml), by using "/~a1Pha" instead of "/paste/a1Pha". The ID is 5 numbers and letters, both cases. For example: /~idnum serves /paste/idnum.htm /=idnum serves /paste/idnum.htm /paste/idnum redirects to /~idnum (to update any old... (0 Replies)
Discussion started by: phillips1012
0 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

5. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

6. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

7. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

8. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

9. UNIX for Dummies Questions & Answers

Difference between "/bin/bash" & "/bin/sh"

what if the difference between #!/bin/sh and #!/bin/bash I wrote a script with the second heading now when i change my heading to the first one ...the script is not executing well....im not getting the required output....any solution to this problem...or do i have to start the... (3 Replies)
Discussion started by: xerox
3 Replies

10. Shell Programming and Scripting

Meaning of "> /dev/null 2>&1"

Hi, I am new into UNIX shell scripting and I am wondering what is the meaning of the below text which appears at the end of each line in the ".sh" file: > /dev/null 2>&1 For example, the line below: sh $HOME/stats/Rep777/Act_777.sh omc omc > /dev/null 2>&1 I know for sure what "sh... (10 Replies)
Discussion started by: salanalani
10 Replies
Login or Register to Ask a Question