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 ...
随机推荐
- [BZOJ 3198] [Sdoi2013] spring 【容斥 + Hash】
题目链接:BZOJ - 3198 题目分析 题目要求求出有多少对泉有恰好 k 个值相等. 我们用容斥来做. 枚举 2^6 种状态,某一位是 1 表示这一位相同,那么假设 1 的个数为 x . 答案就是 ...
- Java学习IO篇
来吧,同志们,为复习网络编程做准备-- 一.理论准备 流是个抽象的概念,是对输入输出设备的抽象,Java程序中,对于数据的输入/输出操作都是以"流" ...
- Android开源项目发现--- 工具类依赖注入DI篇(持续更新)
通过依赖注入减少View.服务.资源简化初始化,事件绑定等重复繁琐工作 1. AndroidAnnotations(Code Diet) android快速开发框架 项目地址:https://gith ...
- ? super T ? extends T
? super T ?保存的是 T类型或者T类型的父类 ? extends T ?保存的是 T类型或者T类型的子类
- 为什么Nhibernate中属性和方法必须Virtual的
如果你曾经用过NHibernate 2.0或者更高的版本,那您一定碰到过下面的错误:NHibernate.InvalidProxyTypeException: The following types ...
- 怒刷BZOJ记录(二)1038~10xx
我实在是太弱了...不滚粗只能刷BZOJ了...这里来记录每天刷了什么题吧. 2015-8-13: 正式开始! 1030[JSOI2007]文本生成器 | ...
- java Spring使用配置文件读取jdbc.properties
Spring使用配置文件读取jdbc.properties 在beans.xml中加入两个必须的bean [html]<bean id="propertyConfigurer" ...
- DSP知识
自己认为是问题的问题,时常更新,为了记录学习的点点滴滴. 1.什么是boot loader ? DSP 的速度尽快,EPROM 或flash 的速度较慢, 而DSP 片内的RAM很快, 片外的RAM也 ...
- C# Dictionary的xml序列化
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- 两种常用的MySQL官方客户端软件
本博文的主要内容有 .命令行客户端软件---MySQL Command Line Client .MySQL-Workbench客户端软件 1.命令行客户端软件---MySQL Command Lin ...