首页 > 其他 > 详细

显示文件类型

时间:2019-06-22 15:25:02      阅读:79      评论:0      收藏:0      [点我收藏+]

显示文件类型

#如查看   /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

显示文件类型

原文:https://www.cnblogs.com/outsrkem/p/11068816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!