linux - bash 隐藏目录和文件的测试属性是什么

标签 linux bash shell

在 bash 脚本中,要测试目录条目是否为文件夹,我们使用 -d ,

shopt -s dotglob nullglob # to include hidden fille
for entry in *
if [ -d "$entry" ]; then # regular directory, not hidden ones...

要测试文件,-f

if [ -f "$entry" ]; then # regular file, not hidden ones...

隐藏目录的属性是什么? , 和隐藏文件?

最佳答案

Hidden files / directories exist only by name convention in UNIX .他们的名字以点开头:

if [[ -d "${entry}" && "${entry}" =~ ^\. ]] ; then
    echo "${entry} is a hidden folder"
fi

进一步(有趣)阅读:https://plus.google.com/u/0/+RobPikeTheHuman/posts/R58WgWwN9jp

关于linux - bash 隐藏目录和文件的测试属性是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44925369/

相关文章:

c++ - 如何将程序输出重定向为输入

linux - 计算所有文件和文件夹,包括隐藏在 bash 中的文件和文件夹

linux - Ansible Vault 不读取定义的变量

bash - 如何创建秒表 Bash 脚本以不断显示耗时?

python - 从 systemd 运行持久性 python 脚本?

bash - 只想执行shell脚本

c - 为什么线程在 linux 中没有以正确的优先级运行

linux - 如何在 Arm 架构硬件上进行内存测试? (类似于 Memtest86)

linux - Linux内核中memcpy的实现

node.js - 使用 shell 脚本提取 package.json 版本