Display only files and folders that are symbolic l

2019-03-08 10:06发布

Basically I want do the following:

ls -l[+someflags]

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

so the output would look

-rw-r--r--  1 username grp   size date-time    filename -> somedir
-rw-r--r--  1 username grp   size date-time    filename2 -> somsdfsdf

etc.

For example,

to show only directories I have an alias:

alias  lsd  'ls -l | grep ^d'

I wonder how to display only hidden files or only hidden directories?

I have the following solution, however it doesn't display the output in color :(

ls -ltra | grep '\->'

11条回答
Viruses.
2楼-- · 2019-03-08 11:06
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

查看更多
▲ chillily
3楼-- · 2019-03-08 11:08

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)

查看更多
走好不送
4楼-- · 2019-03-08 11:11

Try file type flag and get rid of the appending @

ls -F /home/usr/foo | grep "@" | sed 's/@//'
查看更多
Deceive 欺骗
5楼-- · 2019-03-08 11:13

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 .*
查看更多
迷人小祖宗
6楼-- · 2019-03-08 11:13

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
查看更多
登录 后发表回答