LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-30-2005, 01:35 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 51

Rep: Reputation: 15
suppressing an error message using the "ls" command


hi

Is there a way to suppress the "No such file or directory" error message when using the "ls" command ?

thanks
 
Old 03-30-2005, 01:56 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
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
 
Old 03-30-2005, 02:01 AM   #3
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
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)

I don't want any output at all
 
Old 03-30-2005, 02:21 AM   #4
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
ls nofilehere &> /dev/null
ls nofilehere >& /dev/null

Last edited by gbonvehi; 03-30-2005 at 02:24 AM.
 
Old 03-30-2005, 02:42 AM   #5
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
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
 
Old 03-30-2005, 02:51 AM   #6
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 46
I think the only ways to do that are:

- Re-write the ls source code to not generate errors.

- Don't look for files that aren't there

Last edited by oneandoneis2; 03-30-2005 at 02:53 AM.
 
Old 03-30-2005, 03:23 AM   #7
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,558

Rep: Reputation: 121Reputation: 121
Try to be clear as I don't get what you want

- output the error to a file ?
- output the error to nothing ?
 
Old 03-30-2005, 03:53 AM   #8
basher400
Member
 
Registered: Mar 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by keefaz
Try to be clear as I don't get what you want

- output the error to a file ?
- output the error to nothing ?
sorry.
I want to output to nothing.

I just realized "/dev/null" is not an actual file - I mistakenly concluded that from the syntax of it (am I right?)

everything I output to "/dev/null" is actually outputted to nothing? I didn't know that - if so that's the answer I'm looking for.
 
Old 03-30-2005, 04:01 AM   #9
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
/dev/null is the *NIX black hole - anything that goes there doesn't come out.
 
Old 03-30-2005, 04:04 AM   #10
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,558

Rep: Reputation: 121Reputation: 121
You understand it right, "everything I output to /dev/null is actually outputted to nothing"

from: man 4 null
Quote:
Data written on a null or zero special file is discarded.
 
Old 04-02-2005, 09:01 AM   #11
runlevel0
Member
 
Registered: Mar 2005
Location: Hilversum/Holland
Distribution: Debian GNU/Linux 5.0 (“Lenny”)
Posts: 290

Rep: Reputation: 31
Quote:
Originally posted by basher400
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)

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:

Code:
void ()  { cat /dev/null > $1 ; }

Last edited by runlevel0; 04-02-2005 at 09:04 AM.
 
Old 04-02-2005, 11:08 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,500

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Quote:
void () { cat /dev/null > $1 ; }
As "catenating" /dev/null is kind of no op, this shell function can be simplified and optimized to:
Code:
void ()  { > $1 ; }
 
  


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
FC4 not booting w/ message "ERROR opening /dev/console!!!!: 20" Dimension User Fedora 5 10-24-2005 05:03 PM
FC4 install errors, "diabling IRQ #10" "nobody cares" error message??? A6Quattro Fedora 6 07-20-2005 12:49 PM
error message when pressing "Next" "BIOS Problems" , help ! HeRCuLeSX Fedora 3 07-21-2004 02:37 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM
Error message "Nautilus has no installed viewer capable of displaying" oracle_37 Linux - Software 1 08-02-2003 01:27 AM


All times are GMT -5. The time now is 09:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration