shell 评估文件/目录状态

简介: shell 评估文件/目录状态

Shell 判断文件/目录状态

tags: 监控

  • test-file.sh
#!/bin/bash
# test-file: Evaluate the status of a file
echo "Hey what's the File/Directory name (using the absolute path)?"
read FILE
if [ -e "$FILE" ]; then
  if [ -f "$FILE" ]; then
    echo "$FILE is a regular file."
  fi
  if [ -d "$FILE" ]; then
    echo "$FILE is a directory."
  fi
  if [ -r "$FILE" ]; then
    echo "$FILE is readable."
  fi
  if [ -w "$FILE" ]; then
    echo "$FILE is writable."
  fi
  if [ -x "$FILE" ]; then
    echo "$FILE is executable/searchable."
  fi
else
  echo "$FILE does not exist"
  exit 1
fi
exit

执行:

$ ls 
test    dirname
$ bash test-file.sh
Hey what's the File/Directory name (using the absolute path)?
test
test is a regular file.
test is readable.
test is writable.
$ bash test-file.sh
Hey what's the File/Directory name (using the absolute path)?
dirname
dirname is a directory.
dirname is readable.
dirname is writable.
dirname is executable/searchable.
相关文章
|
Shell Android开发
Android系统 adb shell push/pull 禁止特定文件
Android系统 adb shell push/pull 禁止特定文件
2176 1
|
人工智能 机器人 Shell
【shell】文件读写及read用法
【shell】文件读写及read用法
|
缓存 Shell Linux
【Shell 命令集合 链接器(linker)工具】Linux ld命令 将目标文件与库链接为可执行文件或库文件
【Shell 命令集合 链接器(linker)工具】Linux ld命令 将目标文件与库链接为可执行文件或库文件
1036 0
|
Java 关系型数据库 MySQL
Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
【4月更文挑战第12天】Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
1597 3
|
Shell
Shell 文件包含
10月更文挑战第5天
321 4
|
Unix Shell Linux
LeetCode刷题 Shell编程四则 | 194. 转置文件 192. 统计词频 193. 有效电话号码 195. 第十行
本文提供了几个Linux shell脚本编程问题的解决方案,包括转置文件内容、统计词频、验证有效电话号码和提取文件的第十行,每个问题都给出了至少一种实现方法。
654 6
LeetCode刷题 Shell编程四则 | 194. 转置文件 192. 统计词频 193. 有效电话号码 195. 第十行
|
存储 安全 Shell
上传漏洞利用时,没有回显上传目录怎么连接shell
上传漏洞利用时,没有回显上传目录怎么连接shell
|
Shell Linux 网络安全
在Linux中,如何利用Shell把10台主机的当前时间写到一个文件里边?
在Linux中,如何利用Shell把10台主机的当前时间写到一个文件里边?
|
Shell 测试技术 Linux
Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
540 3
|
Shell Linux 开发工具
在Linux中,如何编写shell脚本将当前目录下大于10K的文件转移到/tmp目录下?
在Linux中,如何编写shell脚本将当前目录下大于10K的文件转移到/tmp目录下?