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 命令可以判斷是否是空文件,
把這段代碼添加到你的腳本裡面就可以過濾了。