LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 01: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, 02:24 PM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

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, 02: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, 02:37 PM   #4
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:20 PM.

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
Open Source Consulting | Domain Registration