What is meant by " file > /dev/null 2>&1 </dev/null "
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ?
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
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 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.
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.
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.