Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2343090
  • 博文数量: 2110
  • 博客积分: 18861
  • 博客等级: 上将
  • 技术积分: 24420
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-05 18:23
文章分类

全部博文(2110)

文章存档

2011年(139)

2010年(1971)

我的朋友

分类: LINUX

2010-03-03 17:58:18

本脚本实现指定目录,打印目录下的文件名(全路径)。不为别的,就为了以后用着方便。

#!/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

阅读(239) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~