-1

Newbie here. Can someone please explain what it means to do something "recursively", in plain language? I have looked at search results for HOURS without finding anything that simply says what it means in plain English. For example, if I use the -r option with chown, what does that do?

Thanks!

James A Mohler
  • 243
  • 4
  • 19
Bill
  • 29
  • 1
  • 17
    To understand recursion, one must first understand recursion. – smcg Nov 26 '12 at 22:58
  • 1
    See also [Resources for improving your comprehension of recursion?](http://programmers.stackexchange.com/q/57243/41651) and [In plain English, what is recursion?](http://programmers.stackexchange.com/q/25052/41651) – Michael Hampton Nov 26 '12 at 22:59
  • 3
    Googling `recursion` gives you the answer (in a cryptic way) in the `did you mean` box – Mark Henderson Nov 26 '12 at 22:59
  • [Recursion](http://catb.org/jargon/html/R/recursion.html) – Wesley Nov 26 '12 at 23:00
  • This is where [Wikipedia comes in handy](http://en.wikipedia.org/wiki/Recursion). Or Google's little joke about it. [Did you mean recursion?](https://www.google.com/search?q=recursion) – HopelessN00b Nov 26 '12 at 23:06

1 Answers1

5

So, in order to curb everyone joking around, here's a serious answer:

To do something recursively in this context means to apply whatever it is that you're doing to all the children of the object you're applying it to.

So, doing chown $HOME takes ownership of your home folder, but only the home folder, nothing inside it.

Doing chown -R $HOME (note the upper-case R) will take ownership of the home folder, and then go into the home folder, find all the objects (files and folders in this case), take ownership of them, and then check to see if those objects have any children that it can take ownership of too. Repeat and rinse until it runs out of things to take ownership of.

v25
  • 748
  • 1
  • 6
  • 13
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • 1
    `/~`? It works perfectly without the `/`, and you don't risk applying it to `/ ~` due to a typo. – pgs Nov 26 '12 at 23:05
  • Thank you sir! I had somewhat gathered that that's what it meant, but I am reluctant to perform an operation on several terabytes of not-backed-up data without KNOWING what it means! Yes, I do plan to back it up, but first I must recover it! – Bill Nov 26 '12 at 23:07
  • 2
    @pgs - ok, so you're picking on the syntax of the particular command I chose? Not particularly constructive given that the example is extremely trivial given that it's only being used to demonstrate a point – Mark Henderson Nov 26 '12 at 23:11
  • 1
    @MarkHenderson It may not be a big deal to you, but I have trashed a server with a similar typo. Fortunately it was cleaning up after an upgrade, and I had good backups, so I only got to start again from scratch. I left work _late_ that night. – pgs Nov 27 '12 at 01:49
  • If in doubt, use a -v on such a recursive command so you see what it is doing and can intervene if what happens is different from what was expected... – rackandboneman Dec 10 '12 at 07:34