Linux shell for loop resolves recursive loop directory structure

Source: Internet
Author: User

Let's summarize the problem of recursive loops in the Linux shell today.
Cause is a group of friends in the group of questions
Question of how to move a few files with more or less empty directories.
In the final analysis, it's a recursive loop problem.

If you've been exposed to a programming language like C, then this is a good understanding
is to constantly call yourself by function.
A big drawback of this approach is that it requires a lot of resources
For example, there is a process call to the fork bomb is self-invocation to engage in

I'll just post the code and explain it briefly.

#!/bin/sh./etc/plus.liba () {for file in ' ls $ ' do if [-D $ '/' $file];then A $ '/' $file else echo $ "/" $file fi done}a/tmp

So this is the whole code.
Through a big loop
And then decide if it's a directory or a file
If it is a file, then echo it out, of course, this script does not function,
If you want to do some processing, you can handle it yourself.
If it is not a file but a directory,
Then call yourself to recycle the current directory again

[Email protected]:/tmp/tmp# sh a.sh/tmp/a/01/tmp/a/1/02/tmp/a/1/asdasf/ashfakjsgba/tmp/a/aaa/tmp/b/03/tmp/tmp/ a.sh

So much to sum up, to be able to add later

This article from "Dashazi's Blog" blog, reproduced please contact the author!

Linux shell for loop resolves recursive loop directory structure

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.