[英]Display only files and folders that are symbolic links in tcsh or bash
基本上我想做以下事情:
ls -l[+someflags]
(或通過其他方式)只顯示符號鏈接的文件
所以 output 看起來
-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'
我想知道如何只顯示隱藏文件或只顯示隱藏目錄?
我有以下解決方案,但它沒有以彩色顯示 output:(
ls -ltra | grep '\->'
在目錄中找到所有符號鏈接:
ls -l `find /usr/bin -maxdepth 1 -type l -print`
對於隱藏文件的列表:
ls -ald .*
對於僅“隱藏”文件夾-點文件夾,請嘗試:
ls -l .**
是的,兩個星號是必需的,否則您也會得到。 和..在結果中。
對於符號鏈接,請嘗試使用符號鏈接程序:
symlinks -v .
(顯示當前目錄下的所有符號鏈接)
ls -l | grep lrw
僅顯示符號鏈接(文件和目錄)。 不過,不確定如何使它們豐富多彩。
ls -lad .*
僅顯示隱藏的文件/目錄
ls -l | grep drw
僅顯示目錄。
要顯示符號鏈接及其鏈接,請執行以下操作:
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
您幾乎可以使用grep解決方案了。 讓我們專注於再次獲得色彩。
嘗試這個:
ls --color=always -ltra | grep '->'
對@ChristopheD給出的可接受答案進行一些改進(由於我沒有足夠的聲譽,因此對可接受的答案進行有條理的評論)
我使用別名
findsymlinks <path> <depth>
別名在哪里
alias findsymlinks "find \!:1 -maxdepth \!:2 -type l -print | xargs ls -l --color=auto"
嘗試使用文件類型標志並擺脫附加的@
ls -F /home/usr/foo | grep "@" | sed 's/@//'
對於(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)
對於bash:
這提供了很好的輸出。
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目錄
用法: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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.