Difference between revisions of "Shell/Directories Revisited"

From Coder Merlin
imported>Anton-krom
m (Editorial review and minor corrections)
 
Line 1: Line 1:
There are useful shortcuts that you can use when specifying a path.
You can use several helpful shortcuts when specifying a path.
* "." (a single period or dot) refers to the ''current'' directory
* "." (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
* ".." (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
Line 6: Line 6:
* To move to a ''grandparent'' directory, we can type {{Key|c}}{{Key|d}}{{Key|Space}}{{Key|.}}{{Key|.}}{{Key|/}}{{Key|.}}{{Key|.}}
* To move to a ''grandparent'' directory, we can type {{Key|c}}{{Key|d}}{{Key|Space}}{{Key|.}}{{Key|.}}{{Key|/}}{{Key|.}}{{Key|.}}


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.
Assume we have a directory named 'parent' with two children, 'childA' and 'childB' and we are inside the 'childB' directory and want to enter the 'childA' directory.
* To move to a ''sibling'' directory, we can type {{Key|c}}{{Key|d}}{{Key|Space}}{{Key|.}}{{Key|.}}{{Key|/}}childA
* To move to a ''sibling'' directory, we can type {{Key|c}}{{Key|d}}{{Key|Space}}{{Key|.}}{{Key|.}}{{Key|/}}childA
=== View the Directory Hierarchy ===
=== View the Directory Hierarchy ===
Sometimes it’s helpful to obtain an overview of our directory hierarchy. We can do this with the '''tree''' command. Let's try:
Sometimes it's helpful to obtain an overview of our directory hierarchy. We can do this with the '''tree''' command. Let's try:


{{ConsoleLine|john-williams@codermerlin:~$ |tree}}
{{ConsoleLine|john-williams@codermerlin:~$ |tree}}

Latest revision as of 13:39, 22 February 2023

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

You can use several helpful shortcuts 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 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