Shell脚本让文件权限更易读

本文提供了一个脚本,用于自动区分目录和文件,并以彩色文字或数字形式显示文件权限,有效解决了文件权限转换错误的问题。

简单的写一个可以自动分别目录或文件并以彩色文字或数字显示文件权限,从而能增加文件权限的易读性,解决了由于文件权限r、w、x(4、2、1)字母和数字之间转换出错的问题。

 

脚本内容如下:

#!/bin/bash
read -p "Input your filename:" filename
test -z $filename && echo You must input a filename! && exit 0
test ! -e $filename && echo That file does not exist! && exit 0
test -f $filename && filetype="regular file"
test -d $filename && filetype="directory"
test -r $filename && perm="readable"
test -w $filename && perm="$perm writeable"
test -x $filename && perm="$perm executable"
echo -e "This is a \e[0;31;40m`echo $filetype`\e[0m and the permission is \e[0;36;40m`echo $perm`\e[0m."
echo -e "The digital permission is \e[0;32;40m`stat -c %a $filename`\e[0m."

功能还在继续增强。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值