Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I haven't found an answer to this in the ls MAN page. Is there a way to not output the result of ls when the result is no such ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    72

    Hide ls output when no such file or directory

    Hi,

    I haven't found an answer to this in the ls MAN page.
    Is there a way to not output the result of ls when the result is no such file or directory?; to only display the output when actual files are found?

    Thank you.

    olacelle

  2. #2
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    Tab key is the solution

    If you are having trouble in typing the name of the file exactly as it is, you can use the TAB key after typing the initials . LS command is configured to work that way i.e it displays an error when the file or folder is not present.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  3. #3
    Linux User saivin's Avatar
    Join Date
    Dec 2008
    Location
    Bengaluru, India
    Posts
    305
    Quote Originally Posted by olacelle View Post
    Hi,

    I haven't found an answer to this in the ls MAN page.
    Is there a way to not output the result of ls when the result is no such file or directory?; to only display the output when actual files are found?

    Thank you.

    olacelle
    Redirecting the standard error is the way. Like this:
    Code:
    ls testme 2> /dev/null
    If you want to make it persistent add alias to your .bashrc file in your home directory as:
    Code:
    echo "alias ls='ls 2> /dev/null' " >> ~/.bashrc
    then run ~/.bashrc so that these changes take effect as
    Code:
    . ~/.bashrc
    The above line is a . (period) followed by a SPACE and then ~/.bashrc. Then if you want to test it, run
    Code:
    ls meow
    A candle looses nothing by lighting other candles. - Khalil Zibran.
    Registered Linux User #490076

  4. #4
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    Perfect solution

    Perfect solution I regret why it didn't come in my mind. Keep it up saivin
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  5. #5
    Just Joined!
    Join Date
    May 2009
    Posts
    72
    I didn't know about the '2>' that's perfect for me!
    Thanks to both of you for your replies.

    olacelle

  6. #6
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    2> is the error redirector

    When ever you execute a command it either ends up as in success or in error . When error occurs you get the error on standard output i.e you monitor . In the case of LS command with wrong input the error was getting displayed on the screen, using the '2>' we have redirected the error to something that graceously takes care of it and doesn't display it on the monitor( STDoutput).
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...