#!/bin/sh
myPath="/var/log/httpd/"
myFile="/var /log/httpd/access.log"
# 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限
if [ ! -x "$myPath"]; then
mkdir "$myPath"
fi
 # 这里的-d 参数判断$myPath是否存在
 if [ ! -d "$myPath"]; then
 mkdir "$myPath"
 fi
 # 这里的-f参数判断$myFile是否存在
 if [ ! -f "$myFile" ]; then
 touch "$myFile"
 fi
 # 其他参数还有-n,-n是判断一个变量是否是否有值
 if [ ! -n "$myVar" ]; then
 echo "$myVar is empty"
 exit 0
 fi
 # 两个变量判断是否相等
 if [ "$var1" = "$var2" ]; then
 echo '$var1 eq $var2'
 else
 echo '$var1 not eq $var2'
 fi
-f 和-e的区别 
Conditional Logic on Files 
-a file exists. 
-b file exists and is a block special file. 
-c file exists and is a character special file. 
-d file exists and is a directory. 
-e file exists (just the same as -a). 
-f file exists and is a regular file. 
-g file exists and has its setgid(2) bit set. 
-G file exists and has the same group ID as this process. 
-k file exists and has its sticky bit set. 
-L file exists and is a symbolic link. 
-n string length is not zero. 
-o Named option is set on. 
-O file exists and is owned by the user ID of this process. 
-p file exists and is a first in, first out (FIFO) special file or 
named pipe. 
-r file exists and is readable by the current process. 
-s file exists and has a size greater than zero. 
-S file exists and is a socket. 
-t file descriptor number fildes is open and associated with a 
terminal device. 
-u file exists and has its setuid(2) bit set. 
-w file exists and is writable by the current process. 
-x file exists and is executable by the current process. 
-z string length is zero. 

linux判断文件是否存在的更多相关文章

  1. Linux判断文件是否为空,不为空则打印该文件的大小

    Linux判断文件是否为空,不为空则打印该文件的大小,使用到的命令是-s + filename -s filename 如果文件大小大于0,则返回true. 例如: 查看当前目录 # ls -l to ...

  2. linux 判断文件最后更新时间 实现监控日志是否有输出功能

    linux 判断文件最后更新时间 实现监控日志是否有输出功能. 需求:监控log.txt日志文件,超过一分钟没输出内容就认为是停了,则自动启动程序. 用stat 可以看文件的更新时间stat -c % ...

  3. linux 判断文件夹或文件是否存在

    文件夹不存在则创建 if [ ! -d "/data/" ];then mkdir /data else echo "文件夹已经存在" fi 文件存在则删除 i ...

  4. Linux中用st_mode判断文件类型

    Linux中用st_mode判断文件类型 2012-12-11 12:41 14214人阅读 评论(4) 收藏 举报  分类: Linux(8)  C/C++(20)  版权声明:本文为博主原创文章, ...

  5. Linux 用C语言判断文件和文件夹

    Linux 用C语言判断文件和文件夹 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #inc ...

  6. linux shell判断文件,目录是否存在或者具有权限

    在linux中判断文件,目录是否存在或则具有的权限,根据最近的学习以及网上的资料,进行了以下的总结: #!/bin/sh myPath="/var/log/httpd/" myFi ...

  7. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  8. Linux 获取文件时间信息 判断文件是否存在

    获取文件时间戳   (1)查看全部信息: stat e4.txt 范例: [root@localhost ~]# stat e4.txt File: “e4.txt” Size: 0 Blocks: ...

  9. My way on Linux - [Shell基础] - Bash Shell中判断文件、目录是否存在或者判断其是否具有某类属性(权限)的常用方法

    Conditional Logic on Files # 判断文件是否存在及文件类型 -a file exists. #文件存在 -b file exists and is a block speci ...

随机推荐

  1. 如何获取离线安装Chrome扩展程序的包

    最近工作环境限制,有些机器文件只能拿进去,不能拿出来.网络也是内部网络,没法下载东西.工作中常用的一些Chrome扩展应用也没法使用,对于我这类工具爱好者,打击够大.后来想想,既然扩展应用能开发打包上 ...

  2. 数据挖掘之聚类算法Apriori总结

    项目中有时候需要用到对数据进行关联分析,比如分析一个小商店中顾客购买习惯. package com.data.algorithm; import com.google.common.base.Spli ...

  3. hihocoder-1079题解(线段树+离散化)

    一.题目链接 http://hihocoder.com/problemset/problem/1079 二.题意 给定一个长度为L的区间,给你n个子区间,没一个区间涂成一种颜色,问最后这个区间内有几种 ...

  4. April Fools Contest 2017 题解&源码(A,数学 B,数学 C,数学 D,字符串 E,数字逻辑 F,排序,卡时间,G,数学)

    A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard inpu ...

  5. HDU1728-逃离迷宫-BFS

    逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. 状压dp入门第一题 poj3254

    题目链接 http://poj.org/problem?id=3254 转自http://blog.csdn.net/harrypoirot/article/details/23163485 #inc ...

  7. poj_2195Going Home(最小费用最大流)

    poj_2195Going Home(最小费用最大流) 标签: 最小费用最大流 题目链接 题意: 有n*m的矩阵,H表示这个点是一个房子,m表示这个点是一个人,现在每一个人需要走入一个房间,已经知道的 ...

  8. Logstash+Kibana部署配置

    Logstash是一个接收,处理,转发日志的工具.支持系统日志,webserver日志,错误日志,应用日志,总之包括所有可以抛出来的日志类型. 典型的使用场景下(ELK): 用Elasticsearc ...

  9. MVC 统一异常处理

    在出现异常时,我们不希望将错语的原因让客户看见,常常会做一个404错误页面,将所有发生的异常都跳至该页面,并把异常信息写在日志中.步骤如下: 1.让我们看看Global.asax页面Applicati ...

  10. javascript 之原型、原型链-14

    原型 原型是一个对象,每个函数对象(在javascript 之对象中说过函数也是对象 )都有一个属性(prototype)指向这个对象--原型对象,这个对象的作用是让所有对象实例共享原型对象中的属性. ...