LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-15-2007, 02:59 PM   #1
nyheat
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 75

Rep: Reputation: 15
what does this line do?


"command goes here" > /dev/null 2>&1 &


I know what /dev/null is used for
and I know what & is used for in the very end
but what does 2>&1 do?
 
Old 09-15-2007, 03:24 PM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
">" sends the standard output of the command to /dev/null (in this case).

"2>&1" sends the standard error to the same place the standard output is going.

"&" at the end says to run it in background. This gives you your prompt back and allows you to continue with doing other things. The first 2 options are somewhat typical when sending something off to run in background. The presumption is that it will log errors somewhere for you in some other way.

Note that background jobs launched from your terminal session are still tied to your terminal session. If you exit your terminal session you will kill the job.
 
Old 09-15-2007, 03:31 PM   #3
nyheat
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 75

Original Poster
Rep: Reputation: 15
so without the "2>&1" the error would appear on the screen?

I'm running the command through PHP exec()
 
Old 09-15-2007, 03:37 PM   #4
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
yup.

If you were running php from a web page I'm not sure how it would work. But, from the command line, it would output to your terminal.
 
  


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
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 02:42 PM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 02:43 PM
ADSL Router line 1 Mandrake 10. Line 2 is win xp pro virtthemaest Linux - Networking 0 08-05-2004 01:35 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM


All times are GMT -5. The time now is 06:31 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration