[英]Display only files and folders that are symbolic links in tcsh or bash
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所以 output 看起来
-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:(我有以下解决方案,但它没有以彩色显示 output:(
ls -ltra | grep '\->'
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 .*
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) (显示当前目录下的所有符号链接)
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. 仅显示目录。
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): 输出示例(在ln -s / usr / bin moo之后):
./moo -> /usr/bin
You were almost there with your grep solution; 您几乎可以使用grep解决方案了。 let's focus on getting you COLOR again.
让我们专注于再次获得色彩。
Try this: 尝试这个:
ls --color=always -ltra | grep '->'
Improving a little on the accepted answer given by @ChristopheD (coudnt comment on the accepted answer since I dont have enough reputation) 对@ChristopheD给出的可接受答案进行一些改进(由于我没有足够的声誉,因此对可接受的答案进行有条理的评论)
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"
尝试使用文件类型标志并摆脱附加的@
ls -F /home/usr/foo | grep "@" | sed 's/@//'
For (t)csh : 对于(t)csh :
ls --color=always -ltra | grep '\->'
(This is simply pbr's answer but with the hyphen escaped.) (这只是pbr的答案,但连字符已转义。)
Mac OSX Mac OSX
On OSX, ls
works differently, so add this to your ~/.cshrc
file: 在OSX上,
ls
工作原理有所不同,因此请将其添加到~/.cshrc
文件中:
setenv CLICOLOR_FORCE 1 # (equivalent of Linux --color=always)
And then call: 然后调用:
ls -G -ltra | grep '\->' # (-G is equivalent of ls --color)
For bash: 对于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/^/ /'
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
这对我来说很好,但是,如果您要搜索/文件系统根目录,则需要省略proc目录
Usage: foo $path 用法: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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.