假设我有一个目录/dir中,其中有3个符号连接其他目录
/dir/dir11,/dir/dir12和/dir/dir13.我想列出dir包含其中的所有文件dir11,dir12和dir13.
为了更通用,我想列出所有文件,包括目录中符号链接的文件.find .,ls -R等,停止在符号链接,而不导航进入它们进一步列出.
Mic*_*ley 210
可以完成你想要的-L选项ls.它取消引用符号链接.
所以你的命令是:
ls -LR
Run Code Online (Sandbox Code Playgroud)
你也可以用它完成这个
find -follow
Run Code Online (Sandbox Code Playgroud)
该-follow选项指示find遵循指向目录的符号链接.
在Mac OS X上使用
find -L
Run Code Online (Sandbox Code Playgroud)
如-follow已被弃用.
dvo*_*rak 44
find /dir -type f -follow -print
Run Code Online (Sandbox Code Playgroud)
-type f 意味着它将显示真实文件(不是符号链接)
-follow 意味着它将遵循您的目录符号链接
-print 将使它显示文件名.
如果需要ls类型显示,可以执行以下操作
find /dir -type f -follow -print|xargs ls -l
Run Code Online (Sandbox Code Playgroud)
使用ls:
ls -LR
Run Code Online (Sandbox Code Playgroud)
来自'man ls':
-L, --dereference
when showing file information for a symbolic link, show informa?
tion for the file the link references rather than for the link
itself
Run Code Online (Sandbox Code Playgroud)
或者,使用find:
find -L .
Run Code Online (Sandbox Code Playgroud)
从查找联机帮助页:
-L Follow symbolic links.
Run Code Online (Sandbox Code Playgroud)
如果你发现你只想遵循一些符号链接(比如你刚才提到的那些符号链接),你应该看一下-H选项,它只跟随你在命令行上传递给它的符号链接.
小智 5
find -L /var/www/ -type l
# man find
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)-L Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the链接指向的文件的属性,而不是链接本身的属性(除非它是一个损坏的符号链接或查找无法检查链接指向的文件).使用此选项意味着-noleaf.如果稍后使用-P选项,-noleaf仍然有效.如果-L生效且find在搜索期间发现指向子目录的符号链接,则将搜索符号链接指向的子目录.
我知道tree是合适的,但我没有安装树。所以,我在这里有一个非常接近的替代品
find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
Run Code Online (Sandbox Code Playgroud)