二、编写脚本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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)