#!/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

2017.8.23 shell判断文件,目录是否存在或者具有权限的更多相关文章

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

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

  2. shell判断文件,目录是否存在或者具有权限的代码

    核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的 ...

  3. shell判断文件,目录是否存在或者具有权限 (转载)

    转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d6 ...

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

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

  5. shell判断文件/目录是否存在

    https://www.cnblogs.com/37yan/p/6962563.html caution!!! if should be end with fi caution!!! there sh ...

  6. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...

  7. Shell中判断文件,目录是否存在

    一. 具体每个选项对应的判断内容: -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filena ...

  8. shell判断文件是否存在

    转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...

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

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

随机推荐

  1. 联想E431 安装ubuntu16.04

    http://jingyan.baidu.com/article/3c48dd348bc005e10be358eb.html 按照这个教程安装成功!!

  2. day06 元组类型

    一.什么是元组? 元组就是一个不可变的列表 元组的基本使用: 1.用途:  用于存放多个值,当存放多个任意类型的值 2.定义方式:在()内用逗号分隔开多个任意类型的值 t=(1,3.1,'aaa',( ...

  3. oracle中的对象创建及删除语句【原创】

    oracle对象 1.表 a)创建表1 create table students( id number(10), stuno number(10) , sex varchar2(2), age in ...

  4. Java连接SqlServer 2008数据库

    将sqljdbc4.jar包添加到工程 连接SqlServer 2008数据库 import java.sql.Connection; import java.sql.DriverManager; i ...

  5. 几大principal

    1.A class should have only one reason to change. 一个类只负责一件事 2.高层抽象不依赖低层实现

  6. Linux文件管理常用命令用法总结

    1.touch change file timestamps. 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间.若文件不存在,系统会建立一个新的文件.stat,ls -l 可以显示档案的时 ...

  7. 1.5 socket服务器传输文件

    socket服务器代码 # -*- coding: utf-8 -*-import sys,os,time,_thread from socket import * host = 'localhost ...

  8. Android开发 ---Fragment片段布局

    前言 Fragment想必大家不陌生吧,在日常开发中,对于Fragment的使用也很频繁,现在主流的APP中,基本的架构也都是一个主页,然后每个Tab项用Fragment做布局,不同选项做切换,使用起 ...

  9. codeforces983A(数学题)

    A. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  10. 前端关于列表的基础 day47

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="utf-8&qu ...