简体   繁体   English

如何确定linux符号链接是否指向目录或文件

[英]How to determine if a linux symbolic link points to a directory or a file

我有一个包含符号链接的目录-其中一些指向文件,而另一些指向目录-如何在shell脚本中识别那些指向目录的链接(不影响名称无关紧要)

use ls -L option to follow symlinks 使用ls -L选项跟随符号链接

This is the script that I used to differentiate between directories with contents from files/empty directories ( this will work only if directory has some contents -- in my case I am anyway interested in those directories that have some content so I am happy - but do suggest better options if any 这是我用来区分包含文件/空目录内容的目录的脚本(仅当目录包含某些内容时,此脚本才起作用-就我而言,我对那些包含某些内容的目录很感兴趣,因此我很高兴-但是如果有的话,建议更好的选择

cd dir
for i in `ls `
do
      if [ 1 -lt   `ls -l -L $i  | wc -l`  ]
      then
              echo "$i is a non empty directory" 
      else
              echo "$i is either an empty directory or a  file"
      fi
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建指向它自己的符号链接 - linux - how to create symbolic link that points to it self - linux 如何创建指向目标目录中最新目录的符号链接? - How to create a symbolic link that points to the latest directory in a target directory? 如何检测何时在Linux中的符号链接目录中修改了一个文件 - How to detect when one file is modified inside a symbolic link directory in Linux 如何将符号链接文件从Linux复制到Windows,然后再复制到Linux,但仍将其保留为符号链接 - How to copy symbolic link file from Linux to Windows and then back to Linux but still keeping it as a symbolic link 使用符号链接linux时如何使原始文件不被删除 - How to make original file not delete when using symbolic link linux 如何在c中确定linux中的目录或文件 - how to determine directory or file in linux in c 在redhat或centos Linux中的不同目录中具有嵌入式Flash SWF的HTML文件的符号链接 - Symbolic link for html file with an embeded flash swf located in different directory in redhat or centos Linux 安装rpm并将文件放入符号链接目录 - Install rpm and put file into symbolic link directory 确定链接指向的目录条目的类型 - Determine the type of directory entry a link points to 如何为linux web服务器创建符号链接 - How to create Symbolic link for linux web server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM