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

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

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 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/926396.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存