在linux中判断文件,目录是否存在或则具有的权限,根据最近的学习以及网上的资料,进行了以下的总结:
#!/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

  

 

linux 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. 2017.8.23 shell判断文件,目录是否存在或者具有权限

    #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数 ...

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

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

  6. [转] Linux shell判断文件和文件夹是否存在

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

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

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

  8. linux shell 判断文件是否存在等符号

    -a file exists.  -b file exists and is a block special file.  -c file exists and is a character spec ...

  9. Linux shell判断文件和文件夹是否存在(转发)

    #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数 ...

随机推荐

  1. Spring—SSJ集成&声明式事务管理

    1.   课程介绍 1.  SSJ集成;(掌握) 2.  声明式事务管理;(掌握) 什么是三大框架 2.1.  ssh Struts/Struts2 Spring Hibernate 2.2.  ss ...

  2. 基于ROBO-MAS多智能体自主协同 高频投影定位系统

  3. 浅入kubernetes(2):Kubernetes 的组成

    目录 说明 Kubernetes集群的组成 What are containerized applications? What are Kubernetes containers? What are ...

  4. LeetCode 长度最小的子数组

    题目: 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的连续子数组,并返回其长度.如果不存在符合条件的连续子数组,返回 0. 思路: 非常明显用滑动窗口处 ...

  5. 学习记录——使用PHP实现数据增删查改等基本功能(前后端分离)

    萌新初次学习服务器端语言,分享学习经验 实现功能:1.显示数据表    2.对数据进行分页    3.对数据进行增删查改 由于本萌新采用前后端完全分离方案,所以数据传输用的ajax,为了提高代码的复用 ...

  6. oracle数据库psu升级(本实验是将10.2.0.3.12升级到10.2.0.3.15)

    psu升级(本实验是将10.2.0.3.12升级到10.2.0.3.15) 一.解压安装包自定义存放路径为/home/oracle/yjb/psu/10.2.0.3.15cd /home/oracle ...

  7. Lniux 入门:03 用户及文件权限管理

    1.1 实验内容 Linux 中创建.删除用户,及用户组等操作. Linux 中的文件权限设置. 1.2 实验知识点 Linux 用户管理 Linux 权限管理 通过第一节课程的学习,你应该已经知道, ...

  8. Docker Java 镜像基础(四)

    基于官方提供的centos 7.2.1511 基础镜像构建JDK 和tomcat 镜像,先构建JDK镜像,然后在基于JDK镜像构建tomcat镜像 构建 centos:latest 基础镜像: # 下 ...

  9. mac安装Navicat Premium Mac 12 破解版

    参考:https://www.cnblogs.com/lyfstorm/p/11123159.html 激活后:

  10. ctfshow—web—web5

    打开靶机,代码审计 附上代码 <?php error_reporting(0); ?> <html lang="zh-CN"> <head> & ...