Shell - 文件运算符
文件运算符
文件运算符 | 描述 |
-b file | 检测 file 是否为块设备文件 |
-c file | 检测 file 是否为字符设备文件 |
-d file | 检测 file 是否为目录 |
-e file | 检测 file 是否存在 |
-f file | 检测 file 是否存在为普通文件 |
-r file | 检测 file 是否可读 |
-s file | 检测 file 是否为空文件 |
-w file | 检测 file 是否可写 |
-x file | 检测 file 是否可执行 |
-L file | 检测 file 是否符号链接 |
实例
a) 检测 /dev/sr0 是否为块设备文件。
f="/dev/sr0"
if [ -b "$f" ]
then
echo "${f} is a block (buffered) special file."
else
echo "${f} is not a block (buffered) special file."
fi
b) 检测 /dev/null 是否为字符设备文件。
f="/dev/null"
if [ -c "$f" ]
then
echo "${file} is a character (unbuffered) special file."
else
echo "${file} is not a character (unbuffered) special file."
fi
c) 检测 /etc 是否为目录。
f="/etc"
if [ -d "$f" ]
then
echo "${file} is a directory."
else
echo "${file} is not a directory."
fi
d) 检测 /etc/passwd 是否为普通文件。
f="/etc/passwd"
if [ -f "$f" ]
then
echo "${file} is a regular file."
else
echo "${file} is not a regular file."
fi
e) 检测 /bin/mail 是否为符合链接。
f="/bin/mail"
if [ -L "$f" ]
then
echo "${file} is a symbolic link."
else
echo "${file} is not a symbolic link."
fi
f) 检测 /etc/passwd 是否可读。
f="/etc/passwd"
if [ -r "$f" ]
then
echo "${file} is readable."
else
echo "${file} is not readable."
fi
g) 检测 /etc/passwd 是否可写。
f="/etc/passwd"
if [ -w "$f" ]
then
echo "${file} is writable."
else
echo "${file} is not writable."
fi
h) 检测 /etc/passwd 是否可执行。
f="/etc/passwd"
if [ -x "$f" ]
then
echo "${file} is executable."
else
echo "${file} is not executable."
fi
i) 检测 /etc/passwd 是否存在。
f="/etc/passwd"
if [ -e "$f" ]
then
echo "${file} is existent."
else
echo "${file} is nonexistent."
fi
j) 检测 /etc/passwd 是否为空。
f="/etc/passwd"
if [ -s "$f" ]
then
echo "${file} is empty."
else
echo "${file} is not empty."
fi
Shell - 文件运算符的更多相关文章
- (转)Shell——基本运算符
Shell 基本运算符 原文:http://blog.csdn.net/sinat_36053757/article/details/70319481 Shell 和其他编程语言一样,支持多种运算符, ...
- 五、Shell 基本运算符
Shell 基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令 ...
- Shell文件权限和脚本执行
一.预备知识 1.shell的作用 2.常识 (1)Tab键自动补全 使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...
- Linux Shell系列教程之(十七) Shell文件包含
本文是Linux Shell系列教程的第(十七)篇,更多Linux Shell教程请看:Linux Shell系列教程 通过文件包含,可以引用其他文件的内容,也可以将复杂内容分开,使程序结构更加清晰. ...
- 轻松学习Linux之Shell文件和目录属性详解
轻松学习Linux之Shell文件和目录属性详解 轻松学习Linux之理解Sitcky 轻松学习Linux之理解umask 轻松学习Linux之理解SUID&SGUID 本系列多媒体教程已完成 ...
- Shell 文件包含
和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号(.)和文件名中间有一空 ...
- Python第一天 安装 shell 文件
Python第一天 安装 shell 文件 python里面一切都是对象 object 代码缩进:建议用四个空格来缩进,不要用tab键 安装 Linux自带python,windows需要下载m ...
- 用shell脚本新建shell文件并自动生成头说明信息
目标: 新建文件后,直接给文件写入下图信息 代码实现: [root@localhost test]# vi AutoHead.sh #!/bin/bash#此程序的功能是新建shell文件并自动生成头 ...
- makefile 和shell文件相互调用
shell 文件内调用makefile文件: #!/bin/bash cd ctemplate-2.1./configuresudo make -f installcd ../cd Templat ...
随机推荐
- hduoj 1077 Catching Fish 求单位圆最多覆盖点个数
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- [wikioi]数字三角形
http://wikioi.com/problem/1220/ 最基本经典的DP题目,唯一有点意思的是,自底向上计算会更简洁.另外对这种+方式累计的DP,可以直接把原来的存进去,然后再加,本质是不用在 ...
- c++ 名字粉碎(name mangling)
转自Ibm: Name mangling is the encoding of function and variable names into unique names so that linker ...
- 内存管理(memory allocation内存分配)
Memory management is the act of managing computer memory. The essential requirement of memory manage ...
- 14.6.2 Configuring InnoDB for Read-Only Operation
14.6.2 Configuring InnoDB for Read-Only Operation 配置InnoDB只读操作 你可以查询InnoDB 表MySQL 数据目录是一个只读介质,通过启用 - ...
- TCP/IP TELNET & SSH
快速导航 远程登录示例 关于远程登录? 嵌入? 用来控制远程服务器上运行的应用程序字符? 转义? 操作方式? 关于SSH? 远程登录示例 关于远程登录? 网络虚拟终端(Network Virtual ...
- 介绍4款json的java类库 及 其性能测试
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Programming Lan ...
- 转 -- MVC+EF easyui dataGrid 动态加载分页表格
首先上javascript的代码 <script type="text/javascript"> $(function () { LoadGrid(); }) //加载 ...
- (转载)不能启动虚拟机 Unable to open kernel device "\\.\Global\vmx86
(转载)http://blog.csdn.net/shenghuiping2001/article/details/7083153 今天系统加了内存条,设置变了一下: 就启动不起虚拟机了,报错: Un ...
- (转载)获取当前运行的PHP版本信息
(转载)http://www.clovery.org/get-the-php-version-information.html 获取PHP运行环境信息,可以使用下面的函数. <?php phpi ...