Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: listing only symlinks?

Hybrid View

  1. #1

    Default listing only symlinks?

    Is there a way to filter a directory listing to only show symbolic links?

  2. #2
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    1,273

    Default Re: listing only symlinks?

    don't know if it's waterproof, but I just do a ' ls -al | grep .-\> '
    Have a lot of fun!

  3. #3

    Default Re: listing only symlinks?

    Quote Originally Posted by Magic31 View Post
    don't know if it's waterproof, but I just do a ' ls -al | grep .-\> '
    That seems to work...
    I understand everything up to the .-\> portion..
    Does the grep command just look for the -> character? Is that what you're doing?

    Is there a way to show just the opposite? Everything BUT the symbolic links?

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,623

    Default Re: listing only symlinks?

    You could for example take a look at the man page for grep. I will give you a hint. Search for the -v option.
    Henk van Velden

  5. #5

    Default Re: listing only symlinks?

    Quote Originally Posted by hcvv View Post
    You could for example take a look at the man page for grep. I will give you a hint. Search for the -v option.
    Excellent...
    Thanks for the hint.

  6. #6
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    1,273

    Default Re: listing only symlinks?

    Quote Originally Posted by Magic31 View Post
    don't know if it's waterproof, but I just do a ' ls -al | grep .-\> '
    The > is a special symbol (redirect). So thats why the slash (\) is in front of it to indicate it should be read as normal character. The dot basically does the same to not let grep interpret the - as an option switch.

    So basically you filter the ls output with grep to only show lines containing -> , indicating a link. As the > cannot be used as file character it should only return links.

    Quick and dirty

    Hope that clarifies it,
    Wj
    Have a lot of fun!

  7. #7

    Default Re: listing only symlinks?

    That clarifies it.
    Thanks.

    I found that
    ls -al | grep "^l"
    also works to do the same job.

  8. #8
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    1,273

    Default Re: listing only symlinks?

    Quote Originally Posted by outsider787 View Post
    I found that
    ls -al | grep "^l"
    also works to do the same job.
    That probably is the official way
    Have a lot of fun!

  9. #9
    Kevin Nathan NNTP User

    Default Re: listing only symlinks?

    On Thu, 03 Jul 2008 19:46:04 GMT
    Magic31 <Magic31@no-mx.forums.opensuse.org> wrote:

    >
    >outsider787;1832151 Wrote:
    >>
    >> I found that
    >> ls -al | grep "^l"
    >> also works to do the same job.

    >That probably is the official way
    >
    >


    If you make that an alias (for less typing) it will only work if you
    are *in* the directory -- it won't work if you want a listing from a
    different directory. For that, I have this function in my .alias file
    (in my home directory):

    function showsym {
    ls -la $@ | egrep "^l"
    }

    along with all my favorite aliases. Then, in the .bashrc file I call it
    like this:

    test -s ~/.alias && . ~/.alias || true

    so it is loaded when bash starts . . .

    (Actually, I use a little different grep expression, but that's for
    another discussion!)


    --
    Kevin Nathan (Arizona, USA)
    Linux is not a destination, it's a journey -- enjoy the trip!

    Linux 2.6.22.18-0.2-default
    7:51pm up 15:30, 21 users, load average: 0.33, 0.47, 0.45


  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,623

    Default Re: listing only symlinks?

    Quote Originally Posted by outsider787 View Post
    That clarifies it.
    Thanks.

    I found that
    ls -al | grep "^l"
    also works to do the same job.
    Of course it does, but the important thing is: do you know why?
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

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