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

Thread: listing only symlinks?

  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,378

    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
    Join Date
    Jul 2008
    Location
    Voorhout, Netherlands
    Posts
    262

    Default Re: listing only symlinks?

    outsider787 wrote:
    > Is there a way to filter a directory listing to only show symbolic
    > links?
    >
    >


    find ./ -maxdepth 1 -type l -print0 | xargs -0 ls -l

  10. #10
    Kevin Nathan NNTP User

    Default Re: listing only symlinks?

    On Thu, 03 Jul 2008 16:06:03 GMT
    outsider787 <outsider787@no-mx.forums.opensuse.org> wrote:

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


    I have this function in my .alias file (in my home directory):

    function showsym {
    ls -la $@ | egrep "^[^-dpst]"
    }

    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 . . .


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

    Linux 2.6.22.18-0.2-default
    6:21pm up 13:59, 21 users, load average: 0.42, 0.50, 0.60


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
  •