shell之判断文件是否存在
#!/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
fi #两个变量判断是否相等
if [ "$var1" = "$var2" ]; then
echo '$var1 eq $var2'
else
echo '$var1 not eq $var2'
fi
shell之判断文件是否存在的更多相关文章
- shell脚本判断文件类型
转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...
- shell bash判断文件或文件夹是否存在
#shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文 ...
- My way on Linux - [Shell基础] - Bash Shell中判断文件、目录是否存在或者判断其是否具有某类属性(权限)的常用方法
Conditional Logic on Files # 判断文件是否存在及文件类型 -a file exists. #文件存在 -b file exists and is a block speci ...
- Shell中判断文件,目录是否存在
一. 具体每个选项对应的判断内容: -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为真 -f filename 如果 filena ...
- 【原】Shell脚本-判断文件有无进而复制
2016年7月5日某同学在群上求助要编一个判断文件或目录在某路径下有无进而有的就复制粘贴到另一路径下,无的则将代码中断(不往下执行命令)的脚本.逐一完善.模板如下(生产环境可用到路径环境变量) --- ...
- shell下判断文件夹或文件是否存在
文件夹不存在则创建 if [ ! -d "/data/" ];then mkdir /data else echo "文件夹已经存在" fi 文件存在则删除 i ...
- shell bash使用,包括判断文件或文件夹是否存在举例
Linux shell编程——if条件判断 if [ condition ] ;then //一定要注意[] 與裡面的內容要有空格隔开 例如 if [(空格)${a} -eq 3(空格)]; then ...
- shell与python判断文件是否存在
日常运维中,我们会存在每日备份的现象,针对这一种情况可能会要求监控文件是否存在.比较笨拙的方法就是登录上服务器到某个路径下查看文件是否存在,除此之外,我们可以利用shell或者python来编写监控文 ...
- shell判断文件是否存在
转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bi ...
随机推荐
- PHP实现月份自动加1
<?php date_default_timezone_set('PRC'); $date = date("Y-m-d"); $firstday = date('Y-m-01 ...
- Log 日志收集
class Log { private readonly static String DateFormat = "yyyyMMdd"; private readonly stati ...
- Tensorflow2.0学习(一)
站长资讯平台:今天学习一下Tensorflow2.0 的基础 核心库,@tf.function ,可以方便的将动态图的语言,变成静态图,在某种程度上进行计算加速 TensorFlow Lite Ten ...
- Vue引入非npm的js库
Vue引入非npm的js库 Vue项目有时候需要一些没有export的js库,不能通过import引入,那么使用方法如下 1.可以在index.html页面使用script标签引入,当然也可以使用cd ...
- [React] Create a Query Parameter Modal Route with React Router
Routes are some times better served as a modal. If you have a modal (like a login modal) that needs ...
- 008_linuxC++之_类的静态变量和静态函数
(一)看程序 #include <iostream> #include <string.h> #include <unistd.h> using namespace ...
- UCOSIII(一)
一,前后台系统和RTOS 1,前后台系统 早期嵌入式开发没有嵌入式操作系统的概念 ,直接操作裸机,在裸机上写程序,比如用51单片机基本就没有操作系统的概念.通常把程序分为两部分:前台系统和后台系统. ...
- SIGCHLD函数
SIGCHLD的产生条件 子进程终止时 子进程接收到SIGSTOP信号停止时 子进程处在停止态,接受到SIGCONT后唤醒时 借助SIGCHLD信号回收子进程 子进程结束运行,其父进程会收到SIGCH ...
- 1625: 【例 1】反素数 Antiprime
1625: [例 1]反素数 Antiprime [题目描述] 原题来自:POI 2001 如果一个大于等于 1 的正整数 n,满足所有小于 n 且大于等于 1 的所有正整数的约数个数都小于 n 的约 ...
- C# http请求工具类
/// <summary> /// Http请求操作类之HttpWebRequest /// </summary> public class HttpHelper { #reg ...