Use shell commands to traverse directory and subdirectory files and output to text

Source: Internet
Author: User

"Input_dir" represents the current directory, "Output_file" represents the output file, you can make your own changes according to the situation,

1#!/bin/Bash2 functionGetdir () {3      forElementinch`ls$1`4      Do  5dir_or_file=$1"/"$element6         if[ -d $dir _or_file]7          Then 8 Getdir $dir _or_file9         ElseTen             Echo$dir _or_file >>$output _file One         fi   A      Done - } -Input_dir="." theoutput_file="OUT.txt" -Getdir $input _dir

Learn from this: http://www.cnblogs.com/xiaopipi/p/6214673.html hair bo only for the convenience of later viewing

Use shell commands to traverse directory and subdirectory files and output to text

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.