Display only files and folders that are symbolic links in tcsh or bash

后端 未结 11 834
灰色年华
灰色年华 2021-01-30 13:20

Basically I want do the following:

ls -l[+someflags]

(or by some other means) that will only display files that are symbolic links

so t

相关标签:
11条回答
  • 2021-01-30 13:51

    For bash:
    This provides a nice output.

    sl=`find -L /path/to/target -xtype l`; for links in $sl; do ls --color=always -ltra $links; done | sed 's/^/    /'
    
    0 讨论(0)
  • 2021-01-30 13:54

    You were almost there with your grep solution; let's focus on getting you COLOR again.

    Try this:

    ls --color=always -ltra | grep '->'
    
    0 讨论(0)
  • 2021-01-30 13:56

    Find all the symbolic links in a directory:

    ls -l `find /usr/bin -maxdepth 1 -type l -print`
    

    For the listing of hidden files:

    ls -ald .*
    
    0 讨论(0)
  • 2021-01-30 13:58

    To display JUST the symlinks and what they link to:

    find -P . -type l -exec echo -n "{} -> " \; -exec readlink {} \;
    

    To limit to JUST THIS DIR

    find -P .  -maxdepth 1 -type l -exec echo -n "{} -> " \; -exec readlink {} \;
    

    Example output (after ln -s /usr/bin moo):

    ./moo -> /usr/bin
    
    0 讨论(0)
  • 2021-01-30 14:03

    Usage: foo $path

    Uses current path if none specified.

    #!/bin/bash
    
    case "$1" in
    
        -r)
        find $2 -type l -print | while IFS= read line ; do ls -l --color=always "$line"; done
        ;;
    
        --help)
        echo 'Usage: foo [-r] [$PATH]'
        echo    
        echo '-r  Recursive'
        ;;
    
    
        *)
        ls --color=always -ltra $1 | grep '\->'
    esac
    
    0 讨论(0)
  • 2021-01-30 14:04

    Try file type flag and get rid of the appending @

    ls -F /home/usr/foo | grep "@" | sed 's/@//'
    
    0 讨论(0)
提交回复
热议问题