Difference between revisions of "Shell/Directories Revisited"

From Coder Merlin
imported>Anton-krom
Line 1: Line 1:
== Directories (Revisited) ==
There are useful shortcuts that you can use when specifying a path.
There are useful shortcuts that you can use when specifying a path.
* "." (a single period or dot) refers to the ''current'' directory
* "." (a single period or dot) refers to the ''current'' directory

Revision as of 16:20, 12 December 2021

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

There are useful shortcuts that you can use when specifying a path.

  • "." (a single period or dot) refers to the current directory
  • ".." (a double period, or two adjacent dots) refers to the parent directory, relative to wherever you happen to be in the path up to this point

Thus:

  • To move to a parent directory, we can type cdSpace..
  • To move to a grandparent directory, we can type cdSpace../..

Assume we have a directory named 'parent' with two children, 'childA' and 'childB', and we are currently inside the 'childB' directory and want to enter the 'childA' directory.

  • To move to a sibling directory, we can type cdSpace../childA

View the Directory Hierarchy[edit]

Sometimes it’s helpful to obtain an overview of our directory hierarchy. We can do this with the tree command. Let's try:

john-williams@codermerlin:~$  tree

.

└─ Merlin

   ├─ hello

   │  ├─ newFile.txt

   │  └─ out.txt

   ├─ hello2

   └─ hello3

ObserveObserveIcon.png
Observe, Ponder, and Journal: : Section 7
  1. How does the ls command differ from the tree command?
  2. How do you choose to use one over the other?

Remove a Directory[edit]

Let's remove the two directories that we won't be using anymore. We can do this with the rmdir command. Move to the Merlin directory and then remove the hello2 and hello3 directories. Then do a directory listing to see what’s left.

john-williams@codermerlin:~$  cd Merlin

john-williams@codermerlin:~/Merlin$  rmdir hello2

john-williams@codermerlin:~/Merlin$  rmdir hello3

john-williams@codermerlin:~/Merlin$  ls

hello