Recursive -R

a recursive function is one that calls on itself
how is that different on the command line
and what does it exactly do

yes, recursive functions is one example of recursion. Just like cucumber is a vegetable, but a cucumber isn’t the only vegetable, just like recursive function calls isn’t the only recursion.

The specific meaning of “recursive” in this context is “operating on a directory and its contents, including the contents of any subdirectories”.

The word “recursive” is used here, because at least conceptually, this is easily implemented by a recursive algorithm:

procedure check_in_directory (d : directory)
    for each entry e in d             <== recursive exit after last entry in directory
        if e is a file
        if e is a directory
            check_in_directory(e)     <== recursive call

The recursive structure of this procedure matches the recursive definition of a directory:

  • A directory contains zero or more directory entries

  • A directory entry is either a file or a directory

This approach – writing a function whose structure matches the definition of the data type you are processing is often referred to as structural recursion.


The command line is essentially the almighty as far as the computer is concerned. Give a command and expect a response. If you hand the computer a recusive function then it better have a base case that lets it escape or expect a crash (or freeze up, or out-of-memory error). Recursion eats up a lot of memory fast, and in infinite mode it eats it all up. All of it. Then freezes, or crashes, or politely issues a nice error message, depending on the system. Don’t expect happy endings to commands that include recursive operations unless you really know what to expect.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.