顯示文件類型
#如查看 /etc 目錄
[root@localhost ~]# sh test.sh /etc
/etc/ [目錄文件]
#如查看 /etc 目錄下全部文件
[root@localhost ~]# sh test.sh /etc/*
/etc/abrt [目錄文件]
/etc/adjtime [普通文件]
/etc/aliases [普通文件]
/etc/aliases.db [普通文件]
/etc/alsa [目錄文件]
/etc/alternatives [目錄文件]
/etc/anacrontab [普通文件]
............
腳本從這裏開始,新建test.sh文件。
#!/bin/bash
for i in $@
do
if [ -L "$i" ];then
printf "\e[36m%-50s[軟連接文件]\e[0m\n" "$i"
elif [ -f "$i" ];then
printf "\e[37m%-50s[普通文件]\e[0m\n" "$i"
elif [ -d "$i" ];then
printf "\e[34m%-50s[目錄文件]\e[0m\n" "$i"
elif [ -c "$i" ];then
printf "\e[33m%-50s[字符設備文件]\e[0m\n" "$i"
elif [ -b "$i" ];then
printf "\e[33m%-50s[設備塊文件]\e[0m\n" "$i"
elif [ -p "$i" ];then
printf "\e[33m%-50s[管道文件]\e[0m\n" "$i"
elif [ -S "$i" ];then
printf "\e[35m%-50s[套接字文件]\e[0m\n" "$i"
else
printf "\e[32m%-50s[其餘格式文件]\e[0m\n" "$i"
fi
done