在Linux中,可以使用if else
語(yǔ)句結(jié)合[ -d FILE ]
、[ -f FILE ]
、[ -h FILE ]
等條件來(lái)判斷文件的類型。以下是幾種常見的文件類型判斷方法:
if [ -f FILE ]; then
echo "FILE is a regular file"
else
echo "FILE is not a regular file"
fi
if [ -d FILE ]; then
echo "FILE is a directory"
else
echo "FILE is not a directory"
fi
if [ -h FILE ]; then
echo "FILE is a symbolic link"
else
echo "FILE is not a symbolic link"
fi
if [ -r FILE ]; then
echo "FILE exists and is readable"
else
echo "FILE does not exist or is not readable"
fi
以上是幾種常見的文件類型判斷方法,根據(jù)實(shí)際情況可以結(jié)合不同的條件來(lái)判斷文件的類型。