shell 脚本实现的遍历目录修改子目录及其文件权限
2010-06-02 20:22
1196 查看
下面文章是用来递归修改指定目录下文件和自目录权限的一个脚本实现,对于指定文件的修改,可以通过指定后缀名来实现,脚本中sud变量接受指定的后缀名
1 #!/bin/sh 2 # 3 # Filename:list_dir.sh 4 # Author:CaoJiangfeng 5 # Date: 2010-06-01 6 # 7 # The script is used to change file attributes 8 # Define a function 9 10 list_dir( ) { 11 # Traversal parameter $1 12 for file in $ 1 / * 13 do 14 # If it is a directory then treat it ,after it's treated traverse it 15 if [ - d $ file ] ; then 16 echo "$file is directory" 17 chmod 755 $ file 18 list_dir $ file 19 elif [ - f $ file ] ; 20 then 21 echo $ file 22 #suffix=`echo -n $file |cut -f 2 -d '.'` 23 #suffix= echo -n "`echo $file |cut -f 3 -d '.'`" 24 suffix= ` echo - n $ file | awk - F. '{print $NF}' ` 25 #echo "$suffix" 26 echo "$file is file " 27 chmod 644 $file 28 sud= sh # The varable is used to designate which suffix will be modified 29 30 if [ "$suffix" = "$sud" ] ; 31 then 32 chmod 744 $ file 33 echo "$file changed" 34 fi 35 list_dir $ file 36 fi 37 done 38 } 39 40 41 42 # If there is parameter to traverse the specified directory, 43 # otherwise the current directory traversal 44 if [ $ # -gt 0 ] ; 45 then 46 list_dir "$1" 47 else 48 list_dir "." 49 fi |
相关文章推荐
- shell批量修改当前目录及其子目录中文件后缀名称
- Shell脚本遍历目录并批量修改文件编码
- shell脚本 for循环实现文件和目录遍历
- Shell脚本遍历目录并批量修改文件编码
- 使用Shell遍历目录及其子目录中的所有文件
- 使用Shell遍历目录及其子目录中的所有文件方法
- shell小脚本实现上传目录中的所有文件到服务器
- 采用非递归方式遍历目录及其子目录的文件
- Shell脚本实现检测文件是否被修改过代码分享
- 用shell脚本将当前目录中每个文件的文件名及其内容显示出来
- Shell脚本中判断文件,目录是否存在或者具有权限
- 在目录及其子目录下寻找匹配的文件的python实现
- shell脚本递归遍历目录及子目录的例子分享
- 遍历目录及其子目录下面的某类型文件
- shell 脚本实现统计文件夹下目录及文件个数
- linux 对一个目录及其子目录所有文件添加权限
- shell脚本查找指定目录下所有子目录中的同名文件
- C#遍历某目录及其子目录下所有文件的一个例子
- Shell脚本实现根据文件的修改时间来分类文件
- shell脚本实现的修改文件中的字符串(转)