shell脚本遍历目录及其下子目录
2011-05-26 12:35
260 查看
用shell写了个递归遍历目录的脚本,本脚本实现递归遍历指定目录,打印目录下的文件名(全路径)。不为别的,就为了以后用着方便。
#!/bin/sh function scandir() { local cur_dir parent_dir workdir workdir=$1 cd ${workdir} if [ ${workdir} = "/" ] then cur_dir="" else cur_dir=$(pwd) fi for dirlist in $(ls ${cur_dir}) do if test -d ${dirlist};then cd ${dirlist} scandir ${cur_dir}/${dirlist} cd .. else echo ${cur_dir}/${dirlist} fi done } if test -d $1 then scandir $1 elif test -f $1 then echo "you input a file but not a directory,pls reinput and try again" exit 1 else echo "the Directory isn't exist which you input,pls input a new one!!" exit 1 fi
相关文章推荐
- shell脚本遍历目录及其下子目录
- PHP和shell脚本遍历目录及其下子目录
- shell 脚本实现的遍历目录修改子目录及其文件权限
- Linux shell编程 5 ---- 利用shell脚本遍历某个目录下的所有文件
- 递归遍历目录的shell脚本
- shell遍历目录处理特定目录的脚本代码
- linux下遍历目录和文件,删除过期天数目录或文件shell脚本
- shell脚本遍历当前目录下以数字命名的目录,并打印
- shell脚本递归遍历目录及子目录的例子分享
- 用shell脚本将当前目录中每个文件的文件名及其内容显示出来
- Shell脚本:时间相关、遍历目录、for、if、字符串比较、数字比较
- Shell脚本遍历目录
- shell遍历目录处理特定目录的脚本代码
- 使用Shell遍历目录及其子目录中的所有文件
- Shell脚本01 —— 遍历指定目录,找到指定文件
- shell脚本遍历目录文件
- shell脚本 for循环实现文件和目录遍历
- Shell脚本遍历目录并批量修改文件编码
- shell脚本 遍历所有目录
- shell脚本递归遍历目录及子目录的例子分享