显示文件类型

显示文件类型

#如查看   /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
上一篇:python中print输出带颜色的方法详解


下一篇:python字符串各种颜色输出