find或者test查看某一文件夹下某一文件是否存在
2017-03-06 11:03
316 查看
1. find:
find dir -type f -name "*filename*"
eg:
[root@VTB93-PC2 ~]# find /var/www/html -name 'index2.html'
/var/www/html/index2.html
[root@VTB93-PC2 ~]# find /var/www/html -name 'index2.*'
/var/www/html/index2.html
[root@VTB93-PC2 ~]#
2. test:
test -f /dir/filename
可是这样不输出任何内容:
eg:
[root@VTB93-PC2 ~]# test /var/www/html/index2.html
[root@VTB93-PC2 ~]# test /var/www/html/index3.html
[root@VTB93-PC2 ~]#
[root@VTB93-PC2 ~]# test -f /var/www/html/index3.html
所以在后面增加了判断输出内容:
[root@VTB93-PC2 ~]# test -f /var/www/html/index3.html && echo "exists" || echo "not found"
not found
[root@VTB93-PC2 ~]# test -f /var/www/html/index2.html && echo "exists" || echo "not found"
exists
3. 也可以用perl调用系统命令,然后对输出结果进行匹配判断:
eg:
$out = `ll /var/www/html`;
if($out =~ m/index2.html/s){
print "exists";
}else{
print "not found";
}
find dir -type f -name "*filename*"
eg:
[root@VTB93-PC2 ~]# find /var/www/html -name 'index2.html'
/var/www/html/index2.html
[root@VTB93-PC2 ~]# find /var/www/html -name 'index2.*'
/var/www/html/index2.html
[root@VTB93-PC2 ~]#
2. test:
test -f /dir/filename
可是这样不输出任何内容:
eg:
[root@VTB93-PC2 ~]# test /var/www/html/index2.html
[root@VTB93-PC2 ~]# test /var/www/html/index3.html
[root@VTB93-PC2 ~]#
[root@VTB93-PC2 ~]# test -f /var/www/html/index3.html
所以在后面增加了判断输出内容:
[root@VTB93-PC2 ~]# test -f /var/www/html/index3.html && echo "exists" || echo "not found"
not found
[root@VTB93-PC2 ~]# test -f /var/www/html/index2.html && echo "exists" || echo "not found"
exists
3. 也可以用perl调用系统命令,然后对输出结果进行匹配判断:
eg:
$out = `ll /var/www/html`;
if($out =~ m/index2.html/s){
print "exists";
}else{
print "not found";
}
相关文章推荐
- C语言判断文件夹或者文件是否存在的方法
- Java 判断文件或者文件夹是否存在并创建新文件或者文件夹
- C语言判断文件夹或者文件是否存在的方法
- 如何在shell脚本中判断文件或者文件夹是否存在?
- C语言判断文件夹或者文件是否存在的方法【转】
- [C/C++相关]C语言判断文件夹或者文件是否存在的方法
- C语言判断文件夹或者文件是否存在的方法
- 如何在shell脚本中判断文件或者文件夹是否存在?
- java判断文件夹是否存在某一文件 如果存在就删除功能
- C语言判断文件夹或者文件是否存在的方法
- C语言判断文件夹或者文件是否存在的方法
- 如何在shell脚本中判断文件或者文件夹是否存在?
- C语言判断文件夹或者文件是否存在的方法
- c++,c如何查看文件或者目录是否存在
- C语言判断文件夹或者文件是否存在的方法
- C语言判断文件夹或者文件是否存在的方法
- C语言判断文件夹或者文件是否存在的方法
- C++遍历文件夹及判断某一文件或目录是否存在
- Python判断文件或者文件夹是否存在
- 判断文件或者文件夹是否存在