MathCurvesSurfacesWallpaper GroupsGallerySoftwarePOV-Ray
ProgramingLinuxPerl PythonHTMLCSSJavaScriptPHPJavaLang DesignEmacsUnicode ♥

# English Idiom in Unix: Directory Recursively

,

Today, let's discuss something in the category of lingustics.

You know how in unix tools, when you want to delete the whole directory and all sub-directories and files in it, it's referred as “recursive”?

For example, when you want to delete the whole dir in emacs, it prompts this message: “Recursive delete of xx? (y or n) ”. (Note: to be able to delete whole dir in emacs in dired, you'll first need to turn it on. See: emacs dired tutorial.)

Here's another example. A quote from “cp”' man page:

``` -R, -r, --recursive
copy directories recursively
```

A quote from “rsync” man page:

``` …
This would recursively transfer all files from the directory …
-r, --recursive             recurse into directories
…
```

and lots of other tools have a “-r” option, and they all refer to it as “recursive”.

Though, if you think about it, it's not exactly a correct description. All they are trying to say is that the whole dir including all subdirs will be copied. Whether it's done by recursion is not relevant.

“Recursive”, or “recursion”, refers to a particular type of algorithm, or a implementation using that algorithm. Obviously, to process all directory's content does not necessarily mean it must be done by a recursive algorithm. A iteration can do it as well and it's easy to have the full behavior and properties in the result as a recursive approach, such as specifying depth order, level to dive into, etc. (because, dir is a tree, and recursive algorithm is useful for walking the tree data structure but is not necessary, because a tree can be laid out flat. Any path order taken by a recursive approach can be done by just enumerating the nodes in sequence. In fact, iteration approach can be faster and simpler in many aspects. (i wrote a article about this some 10 years ago, see: Trees and Indexes.) Note: this thought about tree and its nodes as a set of node addresses can be applied to any tree data structure, such as lisp's nested syntax, XML. See: Programing Language: Fundamental Problems of Lisp.)

If you look at Windows or Mac OS X world, i don't think they ever refer to dealing with whole dir as “recursive” in user interface. For example, in Windows Vista, while changing properties of a folder, it has this message:

• Apply changes to this folder only.
• Apply changes to this folder, subfolders and files.

Note the second choice. In unix, it would say “Apply changes to this folder recursively.”

So, the word “recursive” used in unixes may be technically incorrect, but more so, it's just not the right phrase. Because, we want to communicate whether the whole content of a directory are processed, not about certain algorithm or how it is implemented. A simple “all the dir's branches/contents” or similar would be more apt.

Recently i was chatting in Second Life with someone (Sleeves). She's typing, while i'm on voice. In part of our conversation, i said “you sounded fine”. Note that it's technically incorrect, because she's typing, not on voice. So she didn't actually make any “sound”. But to say “you typed fine”, or “you chatted fine”, won't get the message across.

That's idiom. When you interpret a idiom logically, it doesn't make much sense, but people understand the particular phrase better anyway. I suspect the “directory recursively” is also a idiom. It seems so natural and really gets the point across, without any ill effects. Even if the implementation actually used a iteration, it doesn't seem to matter.

So the interesting question is, why this idiom works? Or, how it developed?

I think, among programers (which all unix users are in the 1970s), every one knows the concept of recursion, and many unix tools on dir probably are implemented with a recursive algorithm. When you say “… recursively”, the point gets across, because we all understand it, even when we are not actually talking about implementation. The phrase “… directory recursively” is short and memorable, while “… directory and all its contents” or “… directory and all its branches” or “… directory and all its sub-directories and files” are wordy and unwieldy.