Shell script recursively prints all catalog files in the specified directory

Source: Internet
Author: User
#!/bin/bash
#递归打印当前目录下的所有目录文件.  
PRINTF ()
{
ls $ | While read line
#一次读取每一行放到line变量中
do
  [-D $1/$line] && {
         dir= "$1/$line"
         echo $ DIR
      }
     dir1= ' dirname $DIR '
#求路径.
     a= ' ls-f $DIR 1 | grep/| grep "\< $line \>"
     #判断line是不是一个目录.
     if ["$A" = "$line/"];then
         PRINTF "$DIR 1/$line" #递归调用.
       fi
Done
}
PRINTF.


#!/bin/bash
#这个的实现递归总是无法递归到第一层. 
PRINTF ()
{
  ls  | While read line
  do
  pwd
#测试当前路径.
  [-D./$line] &&{
        echo $line
        CD./$line 
    #这里有问题, has not yet recursion has entered the next level,
    #所以就出现了我上面的解法.
        PRINTF 
        }
    Done
}
PRINTF 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.