仅显示 tcsh 或 bash 中符号链接的文件和文件夹

发布于 2024-08-04 17:01:10 字数 489 浏览 5 评论 0原文

基本上我想执行以下操作:(

ls -l[+someflags]

或通过其他方式)仅显示符号链接的文件

,以便输出看起来

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

等。

例如,

仅显示我有别名的目录:

alias  lsd  'ls -l | grep ^d'

我想知道如何仅显示隐藏文件或者只有隐藏目录?

我有以下解决方案,但是它不以颜色显示输出:(

ls -ltra | grep '\->'

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 '\->'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

白芷 2024-08-11 17:01:10

查找目录中的所有符号链接:

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

对于隐藏文件的列表:

ls -ald .*

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 .*
z祗昰~ 2024-08-11 17:01:10

仅对于“隐藏”文件夹 - 点文件夹,请尝试:

ls -l .**

是的,两个星号是必要的,否则您也会得到 .和..在结果中。

对于符号链接,请尝试使用符号链接程序:(

symlinks -v .

显示当前目录下的所有符号链接)

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)

樱花坊 2024-08-11 17:01:10
ls -l | grep lrw 

仅显示符号链接(文件和目录)。但不知道如何让它们变得丰富多彩。

ls -lad .* 

仅显示隐藏文件/目录

ls -l | grep drw

仅显示目录。

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.

-黛色若梦 2024-08-11 17:01:10

仅显示符号链接及其链接到的内容:

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

限制为仅此目录

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

示例输出(在 ln -s /usr/bin moo 之后):

./moo -> /usr/bin

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
淡淡の花香 2024-08-11 17:01:10

您的 grep 解决方案就快完成了;让我们专注于让您再次获得色彩。

试试这个:

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

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

Try this:

ls --color=always -ltra | grep '->'
谁与争疯 2024-08-11 17:01:10

对 @ChristopheD 给出的接受的答案进行一些改进(由于我没有足够的声誉,因此无法对接受的答案发表评论)

我使用别名,

findsymlinks <path> <depth> 

其中别名为

alias findsymlinks "find \!:1 -maxdepth \!:2 -type l -print | xargs ls -l --color=auto" 

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" 
还不是爱你 2024-08-11 17:01:10

尝试文件类型标志并去掉附加的@

ls -F /home/usr/foo | grep "@" | sed 's/@//'

Try file type flag and get rid of the appending @

ls -F /home/usr/foo | grep "@" | sed 's/@//'
怕倦 2024-08-11 17:01:10

对于 (t)csh:(

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

这只是 pbr 的答案,但连字符已转义。)

Mac OSX

在 OSX 上,ls 的工作方式不同,因此将其添加到您的 ~/.cshrc 文件中:

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

然后调用:

ls -G -ltra | grep '\->'  # (-G is equivalent of ls --color)

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)
知足的幸福 2024-08-11 17:01:10

对于 bash:
这提供了很好的输出。

sl=`find -L /path/to/target -xtype l`; for links in $sl; do ls --color=always -ltra $links; done | sed 's/^/    /'

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/^/    /'
黑凤梨 2024-08-11 17:01:10

用法: foo $path

如果未指定,则使用当前路径。

#!/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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文