Views:
24,808β
Votes: 7β
Tags:
command-line
ls
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/875471
Title:
Why is ls -R called "recursive" listing?
ID:
/2017/01/24/Why-is-ls-R-called-_recursive_-listing_
Created:
January 24, 2017
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
-R is for recursion, which could loosely be called βrepeatedlyβ.
Take this code for example:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ mkdir -p temp/a
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ mkdir -p temp/b/1
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ mkdir -p temp/c/1/2
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$ ls -R temp
temp:
a b c
temp/a:
temp/b:
1
temp/b/1:
temp/c:
1
temp/c/1:
2
temp/c/1/2:
The -p
in making directories allows you to mass create directories with a single command. If one or more of the top-middle directories already exist itβs not an error and the middle-lower directories are created.
Then the ls -R
recursively lists every single directory starting with temp and working itβs way down the tree to all the branches.
Now letβs look at a complement to the ls -R
command, ie the tree
command:
$ tree temp
temp
βββ a
βββ b
βΒ Β βββ 1
βββ c
βββ 1
βββ 2
6 directories, 0 files
As you can see tree
accomplishes the same as ls -R
except is more concise and dare I say βprettierβ.
Now letβs look at how to recursively remove the directories we just created in one simple command:
$ rm -r temp
This recursively removes temp
and all the sub-directories underneath it. ie temp/a
, temp/b/1
and temp/c/1/2
plus the middle directories in between.