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 ...
随机推荐
- Phonegap 3.0 获取当前地址位置
新版本的cordova 3.0 中,使用官方的示例可直接获取当前手机的地理位置,前提是手机开启了gps,或可联网. 获取到的是经纬度坐标值等信息,可通过google api 实现通过经纬度获取当前地理 ...
- 【UVA12093】Protecting Zonk (树形DP)
题意: 给定一个有n个节点的无根树,有两种装置A和B,每种都有无限多个.在某个节点X使用A装置需要C1的花费,并且此时与节点X相连的边都被覆盖.在某个节点X使用B装置需要C2的花费,并且此时与节点X相 ...
- 编码问题(.java/.jsp/.js等文件的中文乱码)
乱码的出现是因为编码与解码的不一致造成的,假如你对“中文”两个字进行了gbk格式的保存,却用utf-8格式的解读,是肯定会出现乱码的. 如何避免中文乱码:应用上下统一用一种编码格式. utf-8或者g ...
- group by 替代distinct
SQL> select distinct employee_id,first_name from test1; 107 rows selected. Execution Plan ------- ...
- BZOJ3039: 玉蟾宫&wikioi2491 玉蟾宫
3039: 玉蟾宫 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 430 Solved: 265[Submit][Status] Descriptio ...
- BZOJ1465: 糖果传递
1465: 糖果传递 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 277 Solved: 105[Submit][Status] Descriptio ...
- 【转】Android Listener侦听的N种写法
原文网址:http://blog.csdn.net/ithomer/article/details/7489274 Android中,View的Listener方法,在是否使用匿名类匿名对象时,有各种 ...
- 直接拿来用!最火的android开源项目(一)
不好意思尊重一下作者咯.详情见:csdn:http://www.csdn.net/article/2013-05-03/2815127-Android-open-source-projects
- IIS7 上传 下载文件大小限制的设置
IIS7 上传 下载文件大小限制的设置 本文来自IISBOY网 一.找到修改大小的配置文件和配置节点 本文来自IISBOY网 打开你系统盘(我是C盘),找到 C:\Windows\System32\i ...
- ACM2075_A/B
#include<iostream> int main() { using namespace std; int i,j,count; cin>>count; while(co ...