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

后端 未结 11 835
灰色年华
灰色年华 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 14:06
    ls -l | grep lrw 
    

    shows only symlinks (files and directories). Not sure how to get them colorful, though.

    ls -lad .* 
    

    shows only hidden files/directories

    ls -l | grep drw
    

    shows directories only.

    0 讨论(0)
  • 2021-01-30 14:10

    For only "hidden" folders - dot folders, try:

    ls -l .**
    

    Yes, the two asterisks are necessary, otherwise you'll also get . and .. in the results.

    For symlinks, well, try the symlinks program:

    symlinks -v .
    

    (shows all symlinks under current directory)

    0 讨论(0)
  • 2021-01-30 14:10

    Improving a little on the accepted answer given by @ChristopheD (coudnt comment on the accepted answer since I dont have enough reputation)

    I use an alias

    findsymlinks <path> <depth> 
    

    where the alias is

    alias findsymlinks "find \!:1 -maxdepth \!:2 -type l -print | xargs ls -l --color=auto" 
    
    0 讨论(0)
  • echo > linklist.found && $(for i in `find /path/to/dir/ -type l`; do echo `ls -d --color=always  $i` `echo " -> "`  $(ls -d --color=always `readlink -f $i`) >> linklist.found; echo >> linklist.found;  done;) && cat linklist.found | more
    

    This works good for me however if you will be searching / the filesystem root you will need to omit the proc directory

    0 讨论(0)
  • 2021-01-30 14:13

    For (t)csh:

    ls --color=always -ltra | grep '\->'
    

    (This is simply pbr's answer but with the hyphen escaped.)

    Mac OSX

    On OSX, ls works differently, so add this to your ~/.cshrc file:

    setenv CLICOLOR_FORCE 1   # (equivalent of Linux --color=always)
    

    And then call:

    ls -G -ltra | grep '\->'  # (-G is equivalent of ls --color)
    
    0 讨论(0)
提交回复
热议问题