shellスクリプトを使ってファイルの種類を確認します。
1640 ワード
原文のリンク:http://www.cnblogs.com/outsrkem/p/11068816.html
ファイルタイプを表示
ファイルタイプを表示
# /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
転載先:https://www.cnblogs.com/outsrkem/p/11068816.html