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条回答
The star\"
2楼-- · 2019-03-08 10:52

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

Try this:

ls --color=always -ltra | grep '->'
查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-08 10:57

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" 
查看更多
欢心
4楼-- · 2019-03-08 10:58
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.

查看更多
We Are One
5楼-- · 2019-03-08 10:59

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/^/    /'
查看更多
爷的心禁止访问
6楼-- · 2019-03-08 11:02

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
查看更多
男人必须洒脱
7楼-- · 2019-03-08 11:04

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