在Linux中,可以使用if else
語句結合[ -d FILE ]
、[ -f FILE ]
、[ -h FILE ]
等條件來判斷文件的類型。以下是幾種常見的文件類型判斷方法:
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
以上是幾種常見的文件類型判斷方法,根據實際情況可以結合不同的條件來判斷文件的類型。