Linux test 命令
2016-05-01 00:00
369 查看
摘要: Linux test 命令
Linux test 命令
评估下面三种情况:数值比较,字符串比较,文件比较
数值比较:
字符串比较:
文件比较:
test 命令主要结合的是 if then 语句和 while 语句使用
eg:
Linux test 命令
评估下面三种情况:数值比较,字符串比较,文件比较
数值比较:
比较 | 描述 | 比较 | 描述 |
n1 -eq n2 | n1 是否等于n2 | n1 -le n2 | n1 是否小于等于 n2 |
n1 -ge n2 | n1 是否大于等于n2 | n1 -lt n2 | n1 是否小于 n2 |
n1 -gt n2 | n1 是否大于 n2 | n1 -ne n2 | n1 是否不等于 n2 |
比较 | 描述 | 比较 | 描述 |
str1 = str2 | str1 等于 str2 | str1 \> str2 | str1 大于 str2 |
str1 != str2 | str1 不等于 str2 | -n str1 | str1 长度 大于 0 |
str1 \< str2 | str1 小于 str2(转义\) | -z str2 | str2 长度 等于 0 |
比较 | 描述 |
-d file | file 是否存在 并且是一个目录 |
-e file | file 是否存在 |
-f file | file 是否存在 并且是一个文件 |
-r file | file 是否存在 并且可读 |
-s file | file 是否存在 并且不为空 |
-w file | file 是否存在 并且可写 |
-x file | file 是否存在 并且可执行 |
-O file | file 是否存在 并且被当前用户拥有 |
-G file | file 是否存在 并且默认组为当前组 |
file1 -nt file2 | file1 是否比 file2 新 |
file1 -ot file2 | file1 是否比 file2旧 (创建时间) |
eg:
val1=abc val2='' if [ -z $val2 ] then echo "$val2 the length is 0" else echo "$val2 the length is not 0" fi
相关文章推荐
- apt-get 的基本使用方法
- linux 下配置codeigniter session出错的解决办法
- Linux.fedora23.WORKSTATION简易安装教程(WIN10+Linux双系统)
- linux下c/c++实例之十四c实现的bt软件下载(记录)
- linux下Intel TBB、 Open MPI、OpenMP
- LAMP环境安装之CentOS(一)
- win8及以上2012 R2,virtualbox 5.0.20安装centOS6以上各种注意事项
- Linux文件系统目录结构
- Linux内核学习总结
- linux查看电脑硬件配置
- Linux Mysql 双机热备安装详解
- Linux内核学习总结
- 期末总结:LINUX内核分析与设计期末总结
- linux内核分析综合总结
- Linux内核学习总结
- OK6410 uboot编译以及设置uboot开机自动启动内核
- 【Linux】-----简单易学的安装
- centos编译libcurl库找不到ssl的问题
- linux 静态库与动态库 博客汇集
- Linux内核分析课程总结