LinuxQuestions.org
Visit Jeremy's Blog.
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 06-30-2006, 08:07 PM   #1
attockonian
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Rep: Reputation: 0
What is meant by " file > /dev/null 2>&1 </dev/null "


I looked up for file > /dev/null 2>&1 </dev/null, and all I found said that it would redirect the output of some file to 2. Something like that.

Can somebody please explain me what does this command do ? I am guessing it has to do anything for running an application in background. I am using the following format in /etc/rc.d/rc.local to run my appz.

if [ blah blah]; then
su user_name
cd /myapp/location
./app &
exit
fi

Is there any better way format for running applications ?

Also, how can I run certian programs on startup in KDE ?


Regards ~
 
Old 06-30-2006, 08:52 PM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Quote:
Originally Posted by attockonian
I looked up for file > /dev/null 2>&1 </dev/null, and all I found said that it would redirect the output of some file to 2. Something like that.
Can somebody please explain me what does this command do ? I am guessing it has to do anything for running an application in background. I am using the following format in /etc/rc.d/rc.local to run my appz.
This is from memory.
Everything in Linux is a file, including I/O. There are three standard file descriptors, Standard In (STDIN, file descriptor 0), Standard Output (STDOUT, file descriptor 1) and Standard Error (STDERR, file descriptor 2). /dev/null is the null device, which is like "write only memory". > will write to the specified file (overwriting its contents) and >> will append to the specified file.

I think that the above command will run "file" and redirect STDERR and STDOUT to /dev/null, and get its input from /dev/null.

Quote:
if [ blah blah]; then
su user_name
cd /myapp/location
./app &
exit
fi

Is there any better way format for running applications ?
It depends on what you are trying to achieve. If you give me more details, then I can give you a more meaningful answer.

Quote:
Also, how can I run certian programs on startup in KDE ?
One way is to create a bash script in ~/.kde/Autostart, that runs the program. This will be run each time the specified user logs in. Make sure the script is executable.

I hope this helps
--Ian
 
Old 06-30-2006, 09:08 PM   #3
anirudh.iitm
LQ Newbie
 
Registered: Jun 2006
Location: chennai , india
Distribution: ubuntu
Posts: 26

Rep: Reputation: 15
Quote:
Originally Posted by attockonian
I looked up for file > /dev/null 2>&1 </dev/null, and all I found said that it would redirect the output of some file to 2. Something like that.

Can somebody please explain me what does this command do ? I am guessing it has to do anything for running an application in background.
hi attockonian,i'm a newbie too,so my reply might not be as good as some others,but here's briefly what this command does:

the "file" command will tell you what type of file the particular file is.for eg: "file textdocument "will give an output of "text file"or something like that.
now what the > operator does is give the output to a file instead of your terminal screen.the < does exactly opposite,it takes input from a file rather than ur screen.
the 2> operator appends to end of file rather than overwritng an existing file of the same name.
the & makes the process run in the background.
given all that i'm still not sure what ur command does.for one thing u've got to specify < before >.for another ,both ur input and output file are of the same name,so i'm not sure if the command is valid.

hope this helps.
 
Old 06-30-2006, 09:38 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
file > /dev/null 2>&1 </dev/null

Where did you see this. The "file" part may be a variable part representing any command. The >/dev/null redirects the standard output to /dev/null, throwing it away. The "2>&1" part redirects the "standard error" output of the command to to the stardard output. the "</dev/null" unattaches the console keyboard and uses "</dev/null" instead. This will allow the program to run in the background without being blocked.
 
Old 06-30-2006, 09:45 PM   #5
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
Quote:
Originally Posted by anirudh.iitm
hi attockonian,i'm a newbie too,so my reply might not be as good as some others,but here's briefly what this command does:

the "file" command will tell you what type of file the particular file is.for eg: "file textdocument "will give an output of "text file"or something like that.
now what the > operator does is give the output to a file instead of your terminal screen.the < does exactly opposite,it takes input from a file rather than ur screen.
the 2> operator appends to end of file rather than overwritng an existing file of the same name.
the & makes the process run in the background.
given all that i'm still not sure what ur command does.for one thing u've got to specify < before >.for another ,both ur input and output file are of the same name,so i'm not sure if the command is valid.

hope this helps.
Not quite.

2> redirects STDERR to the specified file. >> is used to append to the end of the file.

& only means to run the process in the background if it appears at the end of the line.

2>&1 redirects STDERR to STDOUT. Since in this case, STDOUT is being redirected to /dev/null, 2>&1 causes both STDERR and STDOUT to /dev/null.

In this case, it is likely that file is any command, not the specific "file" command. If it was the "file" command, then this whole command would do absolutely nothing.

See Here for a good explanation on this.

--Ian

[EDIT]Damn - jschiwal beat me to it[/EDIT]

Last edited by IBall; 06-30-2006 at 09:47 PM.
 
Old 06-30-2006, 10:51 PM   #6
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
nevermind-

Last edited by spooon; 06-30-2006 at 10:52 PM.
 
  


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
I've got a message about "/dev/null: access denied" Saulo SUSE / openSUSE 2 04-14-2006 10:37 AM
Platform-independent "/dev/null" stream redirection? wapcaplet Programming 1 08-12-2005 10:11 PM
/sbin/adsl-start: line 215: 5543 Terminated $CONNECT "$@" >/dev/null 2> ciberrust Linux - Hardware 3 03-27-2005 10:38 AM
'Can a user be created with username as "/dev/null" in an application?' sheetal_govekar Linux - Software 1 08-25-2004 11:31 AM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 04:19 PM

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

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