1. shell判断文件,目录是否存在或者具有权限
  2. #!/bin/sh
  3. myPath="/var/log/httpd/"
  4. myFile="/var /log/httpd/access.log"
  5. 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限

  6. if [ ! -x “$myPath”]; then
  7. error 少一个空格识别不了

  8. if [ ! -x “$myPath” ]; then
  9. mkdir “$myPath”
  10. fi
  11. 这里的-d 参数判断$myPath是否存在

  12. if [ ! -d “$myPath”]; then
  13. mkdir “$myPath”
  14. fi
  15. 这里的-f参数判断$myFile是否存在

  16. if [ ! -f “$myFile” ]; then
  17. touch “$myFile”
  18. fi
  19. 其他参数还有-n,-n是判断一个变量是否是否有值

  20. if [ ! -n “$myVar” ]; then
  21. echo “$myVar is empty”
  22. exit 0
  23. fi
  24. 两个变量判断是否相等

  25. if [ “var1"="var1" = "var1"="var2” ]; then
  26. echo ‘$var1 eq $var2’
  27. else
  28. echo ‘$var1 not eq $var2’
  29. 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.

my log

download.sh

#!/usr/bin/bash
cat  manifest.txt | while read row
do
path=`dirname $row`
# para -d check dir
if [ ! -d "$path"]; then
# error 少一个空格
if [ ! -d "$path" ]; then
mkdir -p "$path"
fi
# para -f check file
if [ ! -f "$row" ]; then
cd  "$path"
wget https://ftp.ncbi.nlm.nih.gov/genomes/${row}
cd -
fi
done

linux判断目录,文件存在等相关推荐

  1. linux文件内核目录,Linux内核目录文件简介

    ●include目录:头文件目录. 1.主目录: ①a.out头文件,定义了a.out执行文件格式和一些宏. ②常数符号头文件,目前仅定义了i节点中i_mode字段的各标志位. ③字符类型头文件.定义 ...

  2. linux模糊查找目录文件,详解Linux查找目录下的按时间过滤的文件

    在维护项目中,有时会指定都一些条件进行过滤文件,并对该批文件进行操作:这时我们将使用shell命令进行操作:直接上代码 #!/bin/sh #BEGIN #`find ./ ! -name " ...

  3. linux 内核 目录文件说明

    本文使用的源代码是Linux kernel 3.9.4. 下载地址:https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x/linux-3.9.4. ...

  4. LINUX内核目录文件说明

    内核空间和用户空间 在下载内核前,我们应该讨论一些重要的术语和事实.首先了解一下内核空间和用户空间 内核空间中存放的是内核代码和数据,而进程的用户空间中存放的是用户程序的代码和数据.不管是内核空间还是 ...

  5. linux判断没有文件夹建一个,2,shell 脚本, 判断一个文件是否存在, 不存在就创建, 存在就显示其路径...

    2,shell 脚本, 判断一个文件是否存在, 不存在就创建, 存在就显示其路径 关于 shell 脚本: 1, 用 Shell 编程, 判断一文件是不是存在, 如果存在将其拷贝到 /dev 目录下. ...

  6. linux的目录(文件夹) 及 静态库 动态库

    1.windows中,一个软件一个独立的文件夹(文件夹下有这个软件的可执行程序,库文件,依赖文件,图标,图片,配置文件,帮助文档,小工具,数据文件等) linux中,一个软件的可执行文件,可能放在 / ...

  7. linux判断目录是否存在命令,linux shell 中判断文件、目录是否存在的方法

    本文主要介绍了linux shell 中判断文件.目录是否存在的方法,分享给大家 -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为 ...

  8. linux下文件或目录是否存在的函数,Linux下的C++程序:判断目录/文件是否存在

    本文中写了两个函数: 1)int IsFileExist(const char* path) 用于检查一个目录是否存在 -1:存在 0:不存在 2)int IsFileExist(const char ...

  9. Python 标准库之 os (获取当前目录、读取/设置环境变量、重命名文件、运行shell命令、创建/删除/查看目录文件、判断目录/文件/存在、获取绝对路径、获取文件名、获取换行符、获取路径分隔符)

    1. os与sys模块的官方解释如下: os This module provides a portable way of using operating system dependent funct ...

最新文章

  1. Windows Storage Server 2008做存储服务器应用案例
  2. oracle 提示i386,新手请教:RAC安装时检测i386软件包未安装,这个怎么处理?
  3. 介绍自定义JDataGrid电子表格版本公式中的函数?
  4. 我的Dojo中有一个Mojo(如何编写Maven插件)
  5. 【OpenCV 例程200篇】69. 连续非周期信号的傅立叶系数
  6. 谷歌母公司2019Q1财报出炉,营收增速放缓,盘后大跌7.34%,市值蒸发700亿刀
  7. kotlin使用spring data jpa(三)
  8. 手机端html本地存储,HTML5 web storage本地存储
  9. python生成器yield原理_python生成器generator,yield
  10. android系统的图标大小,android开发中手机图标大小的问题
  11. 使用wget下载GLDAS数据
  12. 报童问题求解最大利润_选对方法,速解行测最大利润问题
  13. 【信息汇总】北京航空航天大学计算机考研
  14. 笔记本计算机涂硅脂,笔记本cpu怎么更换散热硅脂?笔记本电脑cpu涂硅脂教程
  15. 关于入门小白对java这种面向对象编程语言的封装、继承、多态的理解
  16. 平年和闰年c语言程序,C语言平年,平年闰年问题
  17. 网管必修课 中小企业安全路由器配置
  18. 《精进》(采铜)——读书笔记
  19. 深圳高新区发展专项计划管理办法(征求意见稿)
  20. 文件夹都具有只读属性

热门文章

  1. 技术人如何搭建自己的技术博客
  2. 《Raspberry Pi用户指南》——导读
  3. 中兴物联笔试和面试随记
  4. Duktape 集成
  5. 外文翻译 《How we decide》赛场上的四分卫 第三节
  6. 50个国内外最棒的C/C++源码站点分享
  7. 域密码自助重置系统----绑定私人邮箱信息自助重置(一)
  8. 【资料】wpcap.dll/Packet.dll库中相应函数
  9. Visio绘制功能分解图
  10. 对Android GPS获取位置信息的新研究.