[英]how to know if the file is txt in linux
我有一個代碼,我需要刪除主目錄中的所有.txt
文件。
我做了一個循環,在循環中有 if 命令:
if [ -f $file]
then
fi
現在我需要另一個 if 命令來檢查文件是否為.txt
。
像這樣的東西,腳本確定文件類型呢?
filename=testfile
fileType=$(file $filename | cut -d" " -f2)
if [[ $fileType = "ASCII" ]]
then
echo "$filname is a test file"
else
echo "$filename is a $fileType file, not a text file"
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.