zoukankan      html  css  js  c++  java
  • 使用shell脚本查看文件类型

    显示文件类型

    #如查看   /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
    " "$i"
    
    	elif [ -f "$i" ];then
    		printf  "e[37m%-50s[普通文件]e[0m
    " "$i"
    
    	elif [ -d "$i" ];then
    		printf  "e[34m%-50s[目录文件]e[0m
    " "$i"
    
    	elif [ -c "$i" ];then
    		printf  "e[33m%-50s[字符设备文件]e[0m
    " "$i"
    
    	elif [ -b "$i" ];then
    		printf  "e[33m%-50s[设备块文件]e[0m
    " "$i"
    
    	elif [ -p "$i" ];then
    		printf  "e[33m%-50s[管道文件]e[0m
    " "$i"
    
    	elif [ -S "$i" ];then
    		printf  "e[35m%-50s[套接字文件]e[0m
    " "$i"
    
    	else
    		printf  "e[32m%-50s[其他格式文件]e[0m
    " "$i"
    	fi
    done
    


    作者:Outsrkem
    出处:https://www.cnblogs.com/outsrkem/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    var、let、const
    面向女朋友自我介绍
    ES6——class
    一个错误引发的——对异步回调与for循环(小白错误,大神勿进)
    关于this
    关于作用域
    HTML5 8
    HTML5 7
    HTML5 6
    HTML5 4
  • 原文地址:https://www.cnblogs.com/outsrkem/p/11068816.html
Copyright © 2011-2022 走看看