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