1、test -f file  2、[ -f file ] 3、[[ -f file ]]

[ -f file1 -a -f file2]逻辑与[ -f file1 -o -f file2]逻辑或 [ -f file1] && [ -f file2 ] 一样的 字符串的操作最好加双引号 如-n -z == != 并且比较时等号两边要加空格

###man test

( EXPRESSION )
EXPRESSION is true

! EXPRESSION
EXPRESSION is false

EXPRESSION1 -a EXPRESSION2
both EXPRESSION1 and EXPRESSION2 are true

EXPRESSION1 -o EXPRESSION2
either EXPRESSION1 or EXPRESSION2 is true

-n STRING
the length of STRING is nonzero

STRING equivalent to -n STRING

-z STRING
the length of STRING is zero

STRING1 = STRING2
the strings are equal

STRING1 != STRING2
the strings are not equal

INTEGER1 -eq INTEGER2
INTEGER1 is equal to INTEGER2

INTEGER1 -ge INTEGER2
INTEGER1 is greater than or equal to INTEGER2

INTEGER1 -gt INTEGER2
INTEGER1 is greater than INTEGER2

INTEGER1 -le INTEGER2
INTEGER1 is less than or equal to INTEGER2

INTEGER1 -lt INTEGER2
INTEGER1 is less than INTEGER2

INTEGER1 -ne INTEGER2
INTEGER1 is not equal to INTEGER2

FILE1 -ef FILE2
FILE1 and FILE2 have the same device and inode numbers

FILE1 -nt FILE2
FILE1 is newer (modification date) than FILE2

FILE1 -ot FILE2
FILE1 is older than FILE2

-b FILE
FILE exists and is block special

-c FILE
FILE exists and is character special

-d FILE
FILE exists and is a directory

-e FILE
FILE exists

-f FILE
FILE exists and is a regular file

-g FILE
FILE exists and is set-group-ID

-G FILE
FILE exists and is owned by the effective group ID

-h FILE
FILE exists and is a symbolic link (same as -L)

-k FILE
FILE exists and has its sticky bit set

-L FILE
FILE exists and is a symbolic link (same as -h)

-O FILE
FILE exists and is owned by the effective user ID

-p FILE
FILE exists and is a named pipe

-r FILE
FILE exists and read permission is granted

-s FILE
FILE exists and has a size greater than zero

-S FILE
FILE exists and is a socket

-t FD file descriptor FD is opened on a terminal

-u FILE
FILE exists and its set-user-ID bit is set

-w FILE
FILE exists and write permission is granted

-x FILE
FILE exists and execute (or search) permission is granted

Except for -h and -L, all FILE-related tests dereference symbolic links. Beware that parentheses need to be
escaped (e.g., by backslashes) for shells. INTEGER may also be -l STRING, which evaluates to the length of
STRING.

shell 条件测试语句三种方法的更多相关文章

  1. shell条件测试语句实例-测试apache是否开启

    终于理解了shell条件测试语句"!="和"-n"的用法区别,于是有了如下的shell脚本,做为练习. 第一种方法:测试apache是否开启?字符串测试 #!/ ...

  2. 《shell条件测试语句,字符串测试apache是否开启》

    还得我想了10分钟才明白”!=“和"-n"的用法区别,做个笔记捋一捋 第一种方法:测试apache是否开启?字符串测试 #!/bin/bash web=`/usr/bin/pgre ...

  3. shell条件测试语句

  4. 【第四章】Shell 条件测试表达式

    shell中条件测试的三种格式: 格式1: test 条件表达式格式2: [ 条件表达式 ]格式3: [[ 条件表达式 ]] 使用test: [root@host- ~]# test -f file ...

  5. C#中??和?分别是什么意思? 在ASP.NET开发中一些单词的标准缩写 C#SESSION丢失问题的解决办法 在C#中INTERFACE与ABSTRACT CLASS的区别 SQL命令语句小技巧 JQUERY判断CHECKBOX是否选中三种方法 JS中!=、==、!==、===的用法和区别 在对象比较中,对象相等和对象一致分别指的是什么?

    C#中??和?分别是什么意思? 在C#中??和?分别是什么意思? 1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; ...

  6. Linux 中执行Shell 脚本的方式(三种方法)

    Shell 脚本的执行方式通常有如下三种: (1)bash script-name 或者 sh script-name:(2)path/script-name或者./script-name:(3)so ...

  7. SHELL 中条件语句的运用 if for 条件测试语句

    if条件测试语句可以让脚本根据实际情况自动执行相应的命令.从技术角度来讲,if语句分为单分支结构.双分支结构.多分支结构:其复杂度随着灵活度一起逐级上升. if条件语句的单分支结构由if.then.f ...

  8. 详解linux下批量替换文件内容的三种方法(perl,sed,shell)

    在建设本网站的时候,发现新建了很多的网页,突然发现,每个文件都需要进行修改一样的内容,一个一个打开很是麻烦,所以,总结了一下如何快速修改一个目录下多个文件进行内容替换.第三种方法用的不多 方法一 使用 ...

  9. MSSQL·查询T-SQL语句执行时间的三种方法

    阅文时长 | 0.23分钟 字数统计 | 420.8字符 主要内容 | 1.引言&背景 2.自定义时间变量求差法 3.MSSQL内置方法 4.MSSQL选项开启时间统计 5.声明与参考资料 『 ...

随机推荐

  1. 解决VS2010无法打开,提示无法找到atl100.dll的方法

    这个问题是卸载VS2010一些组件造成的误删问题,且从网上下的atl100.dll通常与自己的VS2010不符 解决方法: 从路径:C:\Program Files\Microsoft Visual ...

  2. urlencode和rawurlencode的区别

    摘自http://blog.csdn.net/doggie1024/article/details/5698615 urlencode:返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将 ...

  3. 用MFC时,如果程序崩溃,检查内存,然后注意GDI数量,在任务管理器里选项-查看列-GDI数量

    用MFC时,如果程序崩溃,检查内存,然后注意GDI数量,在任务管理器里选项-查看列-GDI数量

  4. 2.准备Python编译环境

    2.准备Python编译环境 2.1下载Python2.7.6.tgz.ipython1.2.1.tgz.sqlite-autoconf-3071401.tar.gz 2.2安装Python2.7.6 ...

  5. 8月3日奥威Power-BI V11 视频交流开课啦!

    ) 进群备注:奥威Power-BI V11 在QQ群上不见不散! 主题: Power-BI V11 基于EXCEL数据源快速制作管理驾驶舱 分享交流内容: 1.产品安装与配置(超级简单,傻瓜式安装) ...

  6. WinForm数字小键盘/WPF数字小键盘

    模仿原本的WinForm触摸屏小键盘制作WPF触摸屏小键盘 原WinForm触摸屏小键盘样式(WinForm采用Krypton系列控件)如下图: Designer代码如下: // // BtnNum1 ...

  7. [ROS]3 Linux编程练习

    一起做RGB-SLAM(2)实验 第二讲 从图像到点云 http://www.cnblogs.com/gaoxiang12/p/4652478.html exbot@ubuntu:~$ cd Code ...

  8. Basic认证

    Basic 概述 Basic 认证是HTTP 中非常简单的认证方式,因为简单,所以不是很安全,不过仍然非常常用. 当一个客户端向一个需要认证的HTTP服务器进行数据请求时,如果之前没有认证过,HTTP ...

  9. rpmdb出问题,重建rpmdb库

    1.备份原库 tar cvzf rpmdb-backup.tar.gz /var/lib/rpm 2.删除rpmdb库 rm -f /var/lib/rpm/__db.00* 3.重建库 rpm -- ...

  10. Java基础之线程——管理线程同步方法(BankOperation2)

    控制台程序. 当两个或多个线程共享同一资源时,例如文件或内存块,就需要采取措施,确保其中的一个线程不会修改另一个线程正在使用的资源.当其中的一个线程更新文件中的某个记录,同时另一个线程正在检索这个记录 ...