?
Solved

suppress 'ls' error output

Posted on 2000-01-17
4
Medium Priority
?
3,178 Views
Last Modified: 2012-06-27
When I run 'ls *.c' (for example), and there are no files with .c extension in the directory, I get the following output: "/bin/ls: No match".
This is very nice, but nothing would please me more than making 'ls' shut up when there are no files to show.
0
Comment
Question by:sharone_
  • 2
4 Comments
 

Author Comment

by:sharone_
ID: 2359817
How do I make that happen?
0
 
LVL 2

Accepted Solution

by:
dirc earned 100 total points
ID: 2359907
There is no option that keeps 'ls' silent when there are no matching files. The only solution is to direct the standard error output to someplace like /dev/null, while keeping the standard output to your console.

In Bourne shell (/bin/sh) or Korn shell (/bin/ksh), you can do:

ls *.c 2> /dev/null

Any files that match the *.c pattern will appear as normal. If there are no matching files, nothing will appear.

I don't know of any good solution in C shell (/bin/csh).
0
 
LVL 1

Expert Comment

by:Randyb
ID: 2360426
you could actually write a little filter script that you would run inplace of ls (maybe named lsc for custom ?) it could check for output
and if none then pipe the echo out to /dev/null, otherwise return the output to the standard out (screen ... ).

EH ... I wouldnt bother myself but if the output really bugs you or if you are running it inside another app then at least this is a way to go.
0
 
LVL 1

Expert Comment

by:Randyb
ID: 2360434
sorry dirc,
sometimes you read something and yet do not see .
I think I basically mimiced what you said (just a different approach) ...but yeah you're right.

Have fun !
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question