shell 判断文件和路径

#!/bin/sh

filePath="/Users/xxx" 
fileName="/Users/xxx/xxx"

#这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 
if [ ! -x "$filePath"]; then 
mkdir "$filePath" 
fi

#这里的-d 参数判断$myPath是否存在 
if [ ! -d "$filePath"]; then 
mkdir "$filePath" 
fi

#这里的-f参数判断$myFile是否存在 
if [ ! -f "$fileName" ]; then 
touch "$fileName" 
fi

#其他参数还有-n,-n是判断一个变量是否是否有值 
if [ ! -n "$myVar" ]; then 
echo "$myVar is empty" 
exit 0 
fi

[@more @]

时间: 2024-08-29 19:13:27

shell 判断文件和路径的相关文章

shell判断文件类型和权限

shell  判断文件类型. -d 文件 判断该文件是否存在,并且是否为目录(是目录为真) -e文件 判断该文件是否存在(存在为真) -f文件 判断该文件是否存在,并且是否为文件(是普通文件为真) -r 如果有文件存在 ,判断文件是否具有读权限有读权限返回真-w如果有文件存在 ,判断文件是否具有写权限有写权限返回真-x如果有文件存在 ,判断文件是否具有执行权限有执行权限返回真 在shell中的写法一般是 eg:[空格-e 文件路径 空格] [ -e /tmp/index.php ] [ -e /

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

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

shell判断文件是否存在

转自:http://www.cnblogs.com/sunyubo/archive/2011/10/17/2282047.html 1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. myFile="/var /log/httpd/access.log" 6. 7. # 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 8. if [ ! -x "

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

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 "$m

Shell 判断文件或文件夹是否存在

#shell判断文件夹是否存在 #如果文件夹不存在,创建文件夹 if [ ! -d "/myfolder" ]; then mkdir /myfolder fi #shell判断文件,目录是否存在或者具有权限 folder="/var/www/" file="/var/www/log" # -x 参数判断 $folder 是否存在并且是否具有可执行权限 if [ ! -x "$folder"]; then mkdir &quo

使用shell 判断文件夹或文件是否存在

使用shell 判断文件夹或文件是否存在 判断文件夹是否存在 if [! -d "/etc/open" ];then echo "文件夹/etc/open不存在" esle echo "文件夹/etc/open存在" fi 判断文件是否存在,若存在则删除 if [ ! -f "/etc/filename" ];then echo "文件不存在" else rm -rf /etc/lename echo &q

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

转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d639c118b82a167.html #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x &

shell 判断文件夹或文件是否存在

文件夹不存在则创建 if [ ! -d "/data/" ];then mkdir /data else echo "文件夹已经存在" fi 文件存在则删除 if [ ! -f "/data/filename" ];then echo "文件不存在" else rm -rf /data/filename fi 判断文件夹是否存在 if [ -d "/data/" ];then echo "文件夹存

C#Winform判断文件和路径是否存在

//选择文件夹 FolderBrowserDialog dia = new FolderBrowserDialog(); if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filePath = dia.SelectedPath; Directory.Exists(filePath);//判断文件夹是否存在 } //选择文件 OpenFileDialog dia = new OpenFileDialog()