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.
相关文章
|
1月前
|
Shell Android开发
Android系统 adb shell push/pull 禁止特定文件
Android系统 adb shell push/pull 禁止特定文件
106 1
|
1月前
|
人工智能 机器人 Shell
【shell】文件读写及read用法
【shell】文件读写及read用法
|
1月前
|
Shell Linux API
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解压缩文件 unzip命令 使用指南
110 0
|
1月前
|
Shell Linux C语言
【Shell 命令集合 备份压缩 】Linux 归档和解档文件 cpio命令 使用指南
【Shell 命令集合 备份压缩 】Linux 归档和解档文件 cpio命令 使用指南
51 0
|
1月前
|
算法 Linux Shell
【Shell 命令集合 备份压缩 】Linux 压缩.Z文件 compress命令 使用指南
【Shell 命令集合 备份压缩 】Linux 压缩.Z文件 compress命令 使用指南
40 0
|
1月前
|
缓存 Shell Linux
【Shell 命令集合 链接器(linker)工具】Linux ld命令 将目标文件与库链接为可执行文件或库文件
【Shell 命令集合 链接器(linker)工具】Linux ld命令 将目标文件与库链接为可执行文件或库文件
72 0
|
1月前
|
Shell Linux C语言
【Shell 命令集合 系统设置 】Linux 创建Kickstart文件mkkickstart命令 使用指南
【Shell 命令集合 系统设置 】Linux 创建Kickstart文件mkkickstart命令 使用指南
37 0
|
1月前
|
存储 Shell Linux
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
【Shell 命令集合 备份压缩 】Linux 解码uuencode编码的文件 uudecode 命令 使用指南
45 0
|
1月前
|
安全 Shell Linux
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
【Shell 命令集合 备份压缩 】Linux将可执行文件压缩成gzip格式 gzexe命令 使用指南
61 0
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
70 0