The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 24,328β€…    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: April 8, 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.

⇧ Stop cpu from overheating How to make linux-generic point to 4.9 and not linux-headers-4.4.0-62 after kernel upgrade from 4.4 to 4.9?  β‡©