方法一:

locate_library() { [ ! "$1*" = "`echo $1*`" ]; }

用法:

# Look for PAM (done weirdly due to distribution bugs (e.g. Debian) or the
# crypt library.
if find_func pam_start sysdeputil.o; thenlocate_library /lib/libpam.so.0 && echo "/lib/libpam.so.0";locate_library /usr/lib/libpam.so && echo "-lpam";locate_library /usr/lib64/libpam.so && echo "-lpam";# HP-UX ends shared libraries with .sllocate_library /usr/lib/libpam.sl && echo "-lpam";# AIX ends shared libraries with .alocate_library /usr/lib/libpam.a && echo "-lpam";
elselocate_library /lib/libcrypt.so && echo "-lcrypt";locate_library /usr/lib/libcrypt.so && echo "-lcrypt";locate_library /usr/lib64/libcrypt.so && echo "-lcrypt";
fi

方法二:

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

各种判断标识及含义如下:

-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.

Shell 判断文件是否存在的方法相关推荐

  1. shell判断文件是否存在[转]

    原文出处: http://canofy.iteye.com/blog/252289 shell判断文件,目录是否存在或者具有权限#!/bin/shmyPath="/var/log/httpd ...

  2. python语句结束符_python中判断文件结束符的具体方法

    python中判断文件结束符的方法:可以使用try except语句块来进行判断. 具体使用方法:[try:while True:s = input() except EOFError: pass]. ...

  3. c 判断文件是否存在_C++基础:判断文件是否存在的方法

    C++基础:判断文件是否存在的方法 使用以下几种函数判断文件是否存在 #include <fstream> --> 使用ifstream打开文件流,成功则存在,失败则不存在; #in ...

  4. shell——判断文件是否存在

    初次使用Markdown编辑器来编写博客,希望有不一样的体会 本文通过网络文章来体会下shell中对文件的操作 1.这个编辑器和wiki有点像呢 2.Shell是一个很好用的脚本 以下为shell下的 ...

  5. java判断方法是否存在_java判断文件是否存在的方法

    java判断文件是否存在的方法 发布时间:2020-06-24 13:09:50 来源:亿速云 阅读:140 作者:Leah 本篇文章展示了java判断文件是否存在的具体操作,代码简明扼要容易理解,绝 ...

  6. python中判断文件是否存在的三种方式_Python中判断文件是否存在的方法

    Python中判断文件是否存在的方法 发布时间:2020-08-06 11:15:42 来源:亿速云 阅读:58 作者:小新 这篇文章主要介绍Python中判断文件是否存在的方法,文中介绍的非常详细, ...

  7. python 判断文件的几种方法

    判断文件的几种方法及特点对比 我们知道当文件不存在的时候,open () 方法的写模式与追加模式都会新建文件,但是对文件进行判断的场景还有很多,比如,在爬虫下载的时候,可能需要判断文件是否存在,以免重 ...

  8. python怎么判断一个文件是否存在-python判断文件是否存在的方法

    python如何判断文件是否存在 通常在读写文件之前,需要判断文件或目录是否存在,不然某些处理方法可能会使程序出错.所以最好在做任何操作之前,先判断文件是否存在. python中如何判断文件是否存在? ...

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

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

最新文章

  1. ORA-01111,ORA-01110,ORA-01157报错处理
  2. 利用A、G、DL、P策略来管理网络资源访问权限
  3. aws集群重启_使用自动伸缩组在AWS中运行安全数据库集群
  4. 搜索引擎学习笔记001---lucene简明介绍
  5. 将[a=1,b=2] 转为对象
  6. 编程基础(二)——汇编
  7. redis - 00 在centos安装
  8. 使用js调用dsoframer打开本地文档问题
  9. Tuxedo 中间件学习心得 一
  10. java获取本机外网ip
  11. 凌恩客户文献|《ISME》解析土壤侵蚀对微生物群落结构以及网络功能复杂性影响
  12. STM32 无法使用IAR下载程序问题
  13. 计算机网络连接黄感叹号,电脑网络图标上出现黄色感叹号不能上网解决方法
  14. 京东商品长图功能来啦 不用改图一键生成长图
  15. P1598垂直柱状图
  16. 云终端ncomputingl300服务器,fl300云终端服务器(share fl300)
  17. 向Excel中批量插入图片,自动排版
  18. 电脑莫名奇妙地出现了嘀嗒壁纸,只有下拉的水滴图标,找不到文件所在位置,怎么删除?
  19. 到底什么是瘦AP、胖AP、AP+AC、Mesh?
  20. android动画光影效果图,光影游戏(二):用手机 App 制作电影海报风格图片

热门文章

  1. 3秒的你对战“它”有没有胜算——quicksort
  2. 20170922前端第四天
  3. 数据库using 自动关闭连接
  4. dedeCMS采集内容无需写规则方法
  5. 西安理工大学计算机就业,西安理工大学毕业以后就业的去向
  6. 无需破解,神器Python帮你免费获取资源
  7. hhpoker!这份入门级线上玩家基本生存法则
  8. android模拟器快照,启用快照后,Android模拟器失败
  9. Android笔记:判断是否为模拟器(实测夜神通过)
  10. dlib 人脸识别及表情分析