if [ -z `要判断输出的命令` ]
do sth here
else
do sth here
if
㈡ linux用C如何判断一个目录是否为空
下面的程序在solaris8、gcc编译通过的,如果一个目录是空的,输出为2。
QUOTE: #include #include #include int main(int argc , char **argv){DIR *dirp;int num=0;dirp = opendir(argv[1]);
while (dirp) {
if ( readdir(dirp) != NULL)++num;elsebreak;}closedir(dirp);
printf("%d\n",num);
}shell中判断目录为空
㈢ linux判断是不是文件且非空
比如当前目录下有个文件名称为abc.txt
如果 要判断abc.txt是不是标准文件可以使用-f参数
if [ -f ./abc.txt ];then
echo "abc.txt is regular file"
fi
要判断是否为空,使用-s参数
if [ -s ./abc.txt ];then
echo "abc.txt is not empty!"
fi
简单的可以这样写
[ -f "./abc.txt" ] && echo 'filename is file!' || [ -s "./abc.txt" ] && echo 'filename is not empty!'
另外文件类型除了普通文件还有很多
-L 文件是一个符号链接
-b 文件是一个块设备
-c 文件是一个字符设备
-p 文件是一个管道
-S 文件是一个socket
-t 文件与一个终端相关联
㈣ 关于linux,shell脚本中怎样判断文件是否有内容
可以用“test 条件表达式”进行测试,如:test -f /etc/fstab 测试文件/etc/fstab文件是否存在
-e File 如果文件File存在(Exist),则为True
-s File 如果文件File存在且文件大小(Size)大于零,则为True
-f File 如果文件File存在且是普通文件(File),则为True
-d File 如果文件File存在且是目录(Directory),则为True
-b File 如果文件File存在且是块(Block)特殊文件,则为True
-c File 如果文件File存在且是字符(Character)特殊文件,则为True
-L File 如果文件File存在且是符号链接(Link)文件,则为True
-r File 如果文件File存在且是可读的(Readable),则为True
-w File 如果文件File存在且是可写的(Writable),则为True
-x File 如果文件File存在且是可执行的(Executable),则为True
-O File 如果文件File存在且属于当前用户(Owner),则为True
-G File 如果文件File存在且属于当前用户组(Group),则为True
File1 -nt File2 如果文件File1新于(Newer Then) File2,则为True
File2 -ot File2 如果文件File1旧于(Older Then) File2,则为True
㈤ linux 判断输出为空的问题
ifconfig -a | awk ifconfig | awk '{print $1 }' | grep eth0
这条命令本身是有问题的,可分开执行验证。
ifconfig -a | awk ifconfig 输出就是空
ifconfig -a | awk ifconfig | awk '{print $1 }' | grep eth0 输出肯定是空
按照你的表述,应该下面这条命令可以搞定:
ifconfig -a|awk /eth0/|awk '{print $1}'
或
ifconfig -a | awk '/eth0/ {print $1}'
㈥ linux下有函数可以直接判断一个目录是否为空吗 csdn
用man 3 printf 就可以看到头文件。有时有些函数的查看需要不同的man库,具体可以看一下 man man。
㈦ linux shell if [[ ! -z $1 ]];是什么意思
判断第一个参数不为空
!非
-z 在if里的意思是 空
$1 第一个参数
[ ! -z $1 ],这是需要返回一个值0或者1
最后结果是 if[1]或者if[0]
㈧ linux 判断一个目录是不是为空的
while(dq = readdir(dir)){
if(strcmp(dq->d_name,".")==0||strcmp(dq->d_name,"..")==0)
continue;//这里可以忽略"."和".."
else if(dq->d_type == DT_DIR){
printf("目录:%s\n",dq->d_name);
char buf[256]={};
sprintf(buf,"%s/%s",path,dq->d_name);
rmdir(buf);
del_dir(buf);
}
else
printf("文件:%s\n",dq->d_name);
}这里是遍历整个目录的代码
给我13亿个赞,不要多
㈨ Linux如何过滤空文件
if test ! -s file 命令可以判断是否是空文件,
把这段代码添加到你的脚本里面就可以过滤了。