Linux shell在当前文件夹内创建文件、查看文件权限、修改文件权限

创建文件

#创建文件
#!/bin/bash
now_path=`pwd`
echo "当前目录为:" $now_path
read -p "输入文件名" filepath
if [ ! -e $now_path/$filepath ]
then
        touch $now_path/$filepath
else
        echo "file is exist!"
fi

查看文件权限

#查看文件权限
#!/bin/bash
now_path=`pwd`
read -p "输入文件名:  " filename
filepath=$now_path/$filename
echo "当前文件为: " $filepath
if [ -e $filepath ]
then
        if [ -r $filepath ]
        then
                echo "文件可读"
        fi
         if [ -w $filepath ]
        then
                echo "文件可写"
        fi

         if [ -x $filepath ]
        then
                echo "文件可运行"
        fi
else
        echo "file not exist!"
fi

修改文件权限

#修改文件权限
now_path=`pwd`
read -p "请输入要修改的文件名" filename
filepath=$now_path/$filename
echo $filepath
if [ -e $filepath ]
then
        echo "您要修改权限的文件为:" $filepath
        read -p "输入权限" power
        if [ -n $power ]
        then
                if [[ $power = *x* ]]
                then
                        chmod +x $filepath
                fi
                if [[ $power = *w* ]]
                then
                        chmod +w $filepath
                fi
                if [[ $power = *r* ]]
                then
                        chmod +r $filepath
                fi

        else
                echo "is null! please input again!"
        fi
else
        echo "file not exist! you should create the file!"
fi

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值