栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux系统shell脚本for循环实战之目录权限

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux系统shell脚本for循环实战之目录权限

Linux系统shell脚本for循环实战之目录权限
  • 一、脚本要求
  • 二、编写脚本
  • 三、执行脚本

一、脚本要求

1.要求输入任意目录:
若目录不在,输出该目录不存在
若目录存在,输出该目录下的文件或目录,且列出其权限

二、编写脚本
[root@192 scripts]# cat ./found_file.sh 
#!/bin/bash
########################################
#Author:jeven
#time:Sun 15 May 2022 09:26:22 PM CST
#filename:found_file.sh
#Script description:
########################################
read -p "please input a dir :" dir
if [ "$dir" == "" -o ! -d "$dir" ];then
	echo "the $dir is not exist!"
	exit 1
	fi
FILE=$( ls  "$dir")
for filename in $FILE
do
	perm=""
	test -r "$dir/$filename" && perm="$perm readable"
	test -w "$dir/$filename" && perm="$perm writable"
	test -x "$dir/$filename" && perm="$perm executable"
	echo "the file $dir /$filename 's permission is $perm "
done

三、执行脚本
[root@192 scripts]# ./found_file.sh 
please input a dir :/data/mysql
the file /data/mysql /file0 's permission is  readable writable 
the file /data/mysql /file1 's permission is  readable writable 
the file /data/mysql /file10 's permission is  readable writable 
the file /data/mysql /file2 's permission is  readable writable 
the file /data/mysql /file3 's permission is  readable writable 
the file /data/mysql /file4 's permission is  readable writable 
the file /data/mysql /file5 's permission is  readable writable 
the file /data/mysql /file6 's permission is  readable writable 
the file /data/mysql /file7 's permission is  readable writable 
the file /data/mysql /file8 's permission is  readable writable 
the file /data/mysql /file9 's permission is  readable writable 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/887272.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号