suppressing an error message using the "ls" command
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
2> /dev/null
can redirect the error messages to /dev/null or use some other file if you are interested in the error messages.
for ex
ls asdf 2> /dev/null
Originally posted by zeropash 2> /dev/null
can redirect the error messages to /dev/null or use some other file if you are interested in the error messages.
for ex
ls asdf 2> /dev/null
thanks.
can I redirect it to null or to nothing, instead to a file?
something like:
ls nofilehere > null
(of course this create a "null" file with the output and I still get the output to my screen)
Originally posted by gbonvehi ls nofilehere &> /dev/null
ls nofilehere >& /dev/null
"ls nofilehere >& /dev/null" works on getting no print to the screen - that's progress but the output still goes to "/dev/null" which I want to prevent
can I redirect it to null or to nothing, instead to a file?
something like:
ls nofilehere > null
(of course this create a "null" file with the output and I still get the output to my screen)
I don't want any output at all
Code:
runlevel0@soviet ~/tmp $ ls comaro 2> /dev/null (first attempt, no output)
runlevel0@soviet ~/tmp $ ls comaro (w/o redirecting)
ls: comaro: No such file or directory (STDERR output)
/dev/null is no a file at all !!
It's the Original Unix Black Hole((TM), a device which has no actual device attached.
It's a device leading to the Unknown Dimension. Note that the /dev filesystem hosts device nodes, not files. You can see this with the file command:
Code:
file /dev/null
/dev/null: character special (1/3)
while for a text file:
file /etc/hosts
/etc/hosts: ASCII English text
The '2>' part of the command says that the STDERR (the standard error output) should be written to /dev/null (2 stands for STDERR and the '>' sign is a redirector).
Keeping it simple: ls -l 2> /dev/null sends the error outpout to a void device which is writable.
Another trick you can do with /dev/null is 'nulling' or voiding a file, writing the content of /dev/null (nothing) to that file:
Code:
#! /bin/sh
# void.sh
# simple script to set a text file to 0 bits
# invoque it with: void FILENAME
cat /dev/null > $1
Save this as void.sh and invoke it whith: ./void.sh or place it in your $PATH, or even better add
this to your ~/.bashrc:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.