BONUS: learn directory relationships

This exercise shows directories (folders) and files on my computer and how they are related. Everything that happens on the computer ends up in a file in a directory.


preview

I use these commands in the chapter to build each part of the tree below step by step, to see how files and folders are related.

doe
├── a_file_in_doe
├── .a_hidden_file_in_doe
├── .a_hidden_folder_in_doe
├── aka_grandparent_of_lil
├── aka_grandparent_of_mary
├── aka_parent_of_jane
├── aka_parent_of_john
├── jane
   ├── .a_hidden_file_in_jane
   ├── .a_hidden_folder_in_jane
   ├── aka_aunt_of_lil
   ├── aka_jane_doe
   ├── aka_parent_of_mary
   ├── aka_sibling_of_john
   ├── child_of_doe
   └── mary
       ├── .a_hidden_file_in_mary
       ├── .a_hidden_folder_in_mary
       ├── aka_mary_jane_doe
       ├── child_of_jane
       ├── child_of_sibling_of_john
       ├── cousin_of_lil
       └── grandchild_of_doe
└── john
    ├── .a_hidden_file_in_john
    ├── .a_hidden_folder_in_john
    ├── aka_john_doe
    ├── aka_parent_of_lil
    ├── aka_sibling_of_jane
    ├── aka_uncle_of_mary
    ├── child_of_doe
    └── lil
        ├── .a_hidden_file_in_lil
        ├── .a_hidden_folder_in_lil
        ├── aka_lil_john_doe
        ├── child_of_john
        ├── child_of_sibling_of_jane
        ├── cousin_of_mary
        └── grandchild_of_doe

10 directories, 30 files
C:.\...\PUMPING_PYTHON\DOE
│   .a_hidden_file_in_doe
│   aka_grandparent_of_lil
│   aka_grandparent_of_mary
│   aka_parent_of_jane
│   aka_parent_of_john
│   a_file_in_doe
├── .a_hidden_folder_in_doe
├── jane
│   │   .a_hidden_file_in_jane
│   │   aka_aunt_of_lil
│   │   aka_jane_doe
│   │   aka_parent_of_mary
│   │   aka_sibling_of_john
│   │   child_of_doe
│   │
│   ├── .a_hidden_folder_in_jane
│   └── mary
│       │   .a_hidden_file_in_mary
│       │   aka_mary_jane_doe
│       │   child_of_jane
│       │   child_of_sibling_of_john
│       │   cousin_of_lil
│       │   grandchild_of_doe
│       │
│       └── .a_hidden_folder_in_mary
└── john
    │   .a_hidden_file_in_john
    │   aka_john_doe
    │   aka_parent_of_lil
    │   aka_sibling_of_jane
    │   aka_uncle_of_mary
    │   child_of_doe
    ├── .a_hidden_folder_in_john
    └── lil
        │   .a_hidden_file_in_lil
        │   aka_lil_john_doe
        │   child_of_john
        │   child_of_sibling_of_jane
        │   cousin_of_mary
        │   grandchild_of_doe
        └── .a_hidden_folder_in_lil

questions about directory relationships

There are answers to these questions in this chapter


what is a folder?

A folder (directory) is a box for files, it can also have other folders (directories). It helps keep things that should be together, in one place, the same way a folder in a file cabinet keeps files that should be together in one place.

I keep every project I work on in its own directory. All the code in this book is kept in a folder named pumping_python.


what is a file?

A file is a collection or container for text, like paper we write or print on and keep in a folder. Everything that happens on the computer ends up in files. The name of a file can end with an extension to show what type of file it is. For example


note

  • The code I type is highlighted and comes after something like I type this in the terminal

  • The result of the code I type after I press enter/return on the keyboard comes after something like the terminal shows ...

  • if you get a different result from what I promise then one of two things happened

    • I made a mistake or

    • You made a mistake

    To make sure it is my mistake check that you typed the same thing I typed. If you still have a different result after you check, email jacobitegboje@gmail.com or text 1-469-751-7595 with the error

  • commands are given to the computer with space between arguments or options, for example

    command argument
    command --option
    command argument_1 argument_2 ... argument_N
    command --option_1 --option_2 ... --option_N
    command argument --option
    command --option
    

    Note

    the space is important, it is how the computer knows what command you mean and what arguments or options you are giving, for example

    commandargument_1 argument_2
    

    tells the computer to run a command named commandargument_1 with argument_2 as the argument, while

    command argument_1 argument_2
    

    tells the computer to run a command named command with argument_1 and argument_2 as the arguments

  • options for commands sometimes have a long and short form, for example --long_option could have -l as the short option, which means I can put many short options together like this

    command -abcd
    

    where a, b, c and d are different options

if you have Windows without Windows Subsystem for Linux, some of the commands and terminal output will be different, click on the tab where it shows no WSL, for example

You clicked on WSL/Linux/Mac

You clicked on no WSL


requirements

  • I type this in a terminal to make sure the tree program is installed

    tree
    
  • If it is not installed on the computer, the terminal is my friend, and shows

    tree: command not found
    

    see how to install tree to install tree

  • If it is installed and there is nothing in the directory, the terminal is my friend, and shows

    .
    
    0 directories, 0 files
    
  • If it is installed and there is something in the directory, the terminal is my friend, and shows how they are related.

I type tree

Folder PATH listing
Volume serial number is ABCD:EFGH
C:.
No subfolders exist

The tree program shows how files and folders on a computer are related, this helps to know how to go from one folder to another, because it shows the way I can go.

It is easier to go where I want, if I know where I am.

Click here to see what directory I am in


how to install tree


how to install tree on Linux/Windows Subsystem for Linux


Attention

Do this only if you are using Linux or Windows Subsystem for Linux and tree is not installed.

Click here if you have MacOS

sudo apt update

I always do a full upgrade (you do not have to)

sudo apt full-upgrade --yes

type this in the terminal to install tree

sudo apt install tree

Click here to see what directory I am in


how to install tree on Windows without Windows Subsystem for Linux


Attention

Do this only if you are using Windows and could not install Windows Subsystem for Linux

Click here if you have MacOS

no need to install tree because it comes with Windows.

Click on the tab that says no WSL to see the commands or results if you have Windows without Windows Subsystem for Linux. These are the commands I use

when you type pwd or tree, the terminal is my friend, and shows \ between folder names, not /. Click the no WSL tab for an example

.../pumping_python/doe
Path
----
C:\...\pumping_python\doe

Your tree will also look different because of different ways of drawing and sorting.

Click here to see what directory I am in


how to install tree on Mac OS


type this in the terminal to install tree

brew install tree

Click here to see what directory I am in


how to see what directory I am in

I start with a check of where I am in the terminal because It is easier to go where I want, if I know where I am. I can do this with the pwd program

pwd

the terminal is my friend, and shows

.../pumping_python
Path
----
C:\...\pumping_python

if I am in the pumping_python folder

  • pwd shows the path/address of the folder I am in

  • pwd means print working directory, it prints the path/address of the directory I am in, to the terminal

    • each / shows a parent-child relationship

    • the first / is for root which is the first folder on the computer

    • the first / is the highest level

    • each \ shows a parent-child relationship

    • C:\ is for root which is the first folder on the computer

    • C:\ is the highest level

    do you want to see every file and folder on your computer as a tree?

    Type this in the terminal

    tree /
    
    tree C:/
    

    it runs for a while because there are many files and folders.

    Use ctrl+c on the keyboard to stop it.

Note


how to change directory

I use the cd program to change directories

cd pumping_python

cd means change directory

the terminal is my friend, and shows

cd: no such file or directory: pumping_python
Set-Location: Cannot find path
              'C:\...\pumping_python'
              because it does not exist

this means the folder I want to go to is not in the folder where I am.


how to make a directory

  • I want to work in a directory named doe, I try to change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe'
                  because it does not exist
    

    doe is not in the pumping_python directory, yet

  • I use mkdir to make doe

    mkdir doe
    

    the terminal is my friend, and shows

    .../pumping_python
    
        Directory: C:\...
    
    Mode            LastWriteTime   Length  Name
    ----            -------------   ------  ----
    d-----    MM/DD/YYYY HH:MM A/PM
    
  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am in the doe folder I just made

  • I use pwd to see where I am

    pwd
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    
    Path
    ----
    C:\...\pumping_python\doe
    

It is easier to go where I want, if I know where I am.


how to see what is in a directory

  • I can use ls to see what is in a directory and see more information about the files and folders in it

    ls
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    this directory is empty

    • ls has a few options. I try ls again with one of them

      ls --all
      

      the terminal is my friend, and shows

      .  ..
      

    Attention

    • on MacOS the terminal is my friend, and shows

      ls: unrecognized option `--all'
      

      --all is the long form of the option, use -a which is the short form of the option

      ls -a
      
    • --all or -a tells ls to show all the things in the directory even those that start with . ( they are hidden by default)

    • I can hide a file or folder if I put . before its name, for example .hidden

    C:\...\pumping_python\doe
    
  • I try to change directory to .

    cd .
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    
  • I try cd with ..

    cd ..
    

    the terminal is my friend, and shows

    .../pumping_python
    
    • I am back in the pumping_python directory

    • .. is for the parent of the directory I am in

    • .. is pumping_python when I am in doe

    • pumping_python is the parent of doe

    • I can change directory from the directory I am in to its parent with cd ..

I know how to see what is in a directory


how to look at directory relationships

  • I use cd to go back to doe

    cd doe
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    
  • I can use the tree program to see the files and folders in a directory and how they are related. I type it in the terminal to see what is in the doe directory

    tree
    

    the terminal is my friend, and shows

    .
    
    0 directories, 0 files
    
    Folder PATH listing
    Volume serial number is ABCD:EFGH
    C:.
    No subfolders exist
    

    there is nothing in doe, it is empty

  • I try to change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    cd: no such file or directory: jane
    
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe\jane'
                  because it does not exist
    

    jane is not a child of doe, yet

  • I use mkdir to make jane

    mkdir jane
    

    the terminal goes back to the command line

  • I use ls to see what is now in doe

    ls
    

    the terminal is my friend, and shows

    jane
    
  • I use tree to show what is in doe

    tree
    

    the terminal is my friend, and shows

    .
    └── jane
    
    2 directories, 0 files
    
    C:.
    └── jane
    
    • jane is a child of doe

    • . is the working directory, which is doe in this case

    • the line in the tree that goes from . to jane shows I can go from doe right to jane

  • I change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    .../pumping_python/doe/jane
    

    I am in jane

  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    • doe is not a child of jane

    • I cannot go from jane to doe this way

  • I change directory back to the parent of jane

    cd ..
    

    the terminal shows

    .../pumping_python/doe
    

  • I try to change directory to john

    cd john
    

    the terminal is my friend, and shows

    cd: no such file or directory: john
    
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe\john'
                  because it does not exist
    

    john is not a child of doe, yet

  • I use mkdir to make john

    mkdir john
    

    the terminal goes back to the command line

  • I use ls to see what is in doe

    ls
    

    the terminal is my friend, and shows

    jane  john
    
  • I use tree to show the folders inside doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── jane
    └── john
    
    3 directories, 0 files
    
    • john is a child of doe

    • . is the working directory, which is doe in this case

    • the line in the tree that goes from . to john shows I can go from doe right to john

  • I change directory to john

    cd john
    

    the terminal is my friend, and shows

    .../pumping_python/doe/john
    

    I am in john

  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    • doe is not a child of john

    • I cannot go from john to doe this way

  • I change directory back to the parent of john

    cd ..
    

    the terminal shows

    .../pumping_python/doe
    
  • I change directory to a hidden folder in doe

    cd .a_hidden_folder_in_doe
    

    the terminal is my friend, and shows

    cd: no such file or directory:
        .a_hidden_folder_in_doe
    

    .a_hidden_folder_in_doe is not in doe, yet

  • I use mkdir to make .a_hidden_folder_in_doe

    mkdir .a_hidden_folder_in_doe
    

    the terminal goes back to the command line

  • I use ls to see what is in doe

    ls
    

    the terminal is my friend, and shows

    jane  john
    
    • .a_hidden_folder_in_doe is hidden

    • I can hide a file or folder if I put . before its name

    • I use ls with the -a option to see everything that is in doe even things that are hidden

      ls -a
      

      the terminal is my friend, and shows

      .  ..  .a_hidden_folder_in_doe  jane  john
      
    Mode            LastWriteTime         Length  Name
    ----            -------------         ------  ----
    d-----    MM/DD/YYYY HH:MM A/PM               .a_hidden_folder_in_doe
    d-----    MM/DD/YYYY HH:MM A/PM               jane
    d-----    MM/DD/YYYY HH:MM A/PM               john
    

    .a_hidden_folder_in_doe is not hidden on Windows without Windows Subsystem for Linux

  • I use tree to show the folders inside doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── jane
    └── john
    
    3 directories, 0 files
    
    • .a_hidden_folder_in_doe is hidden

    • I can hide a file or folder if I put . before its name

    • I can also use tree with the -a option to show things that are hidden

      tree -a
      

      the terminal is my friend, and shows

      .
      ├── .a_hidden_folder_in_doe
      ├── jane
      └── john
      
      4 directories, 0 files
      
      • . is the working directory, which is doe in this case

      • the line in the tree that goes from . to .a_hidden_folder_in_doe shows I can go from doe right to .a_hidden_folder_in_doe

    C:.
    ├── .a_hidden_folder_in_doe
    ├── jane
    └── john
    

    .a_hidden_folder_in_doe is not hidden on Windows without Windows Subsystem for Linux

  • I change directory to .a_hidden_folder_in_doe

    cd .a_hidden_folder_in_doe
    

    the terminal is my friend, and shows

    .../pumping_python/doe/.a_hidden_folder_in_doe
    

    I am in .a_hidden_folder_in_doe

  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    Set-Location: Cannot find path
                  `C:\...\pumping_python\doe\john\lil\doe`
                  because it does not exist
    
    • doe is not a child of .a_hidden_folder_in_doe

    • I cannot go from .a_hidden_folder_in_doe to doe this way

  • I change directory back to the parent of .a_hidden_folder_in_doe

    cd ..
    

    the terminal shows

    .../pumping_python/doe
    
    • I am back in doe

    • .. is for the parent of the directory I am in

    • I can change directory from the directory I am in to its parent with cd ..

    • .. is doe when I am in .a_hidden_folder_in_doe


  • I change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    .../pumping_python/doe/jane
    
  • I use ls to show what is in jane

    ls
    

    the terminal goes back to the command line

    • I use ls with the short form of the --all option

      ls -a
      

      the terminal is my friend, and shows

      .  ..
      

    the terminal goes back to the command line

    jane has no children

  • I use tree

    tree
    

    the terminal is my friend, and shows

    .
    
    0 directories, 0 files
    

    jane has no children

  • I change directory to mary

    cd mary
    

    the terminal is my friend, and shows

    cd: no such file or directory: mary
    

    jane has no children, yet

  • I use mkdir to make mary

    mkdir mary
    

    the terminal goes back to the command line

  • I try to change directory to mary again

    cd mary
    

    the terminal is my friend, and shows

    .../doe/jane/mary
    
    • I am in the mary folder

    • mary is a child of jane

    • jane is a child of doe

  • I change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    cd: no such file or directory: jane
    
    • jane is not a child of mary

    • I cannot go from mary to jane this way

  • I go up a level to the parent of mary

    cd ..
    

    the terminal is my friend, and shows

    .../doe/jane
    

    I am back in jane

  • I change directory to a hidden folder in jane

    cd .a_hidden_folder_in_jane
    

    the terminal is my friend, and shows

    cd: no such file or directory:
        .a_hidden_folder_in_jane
    

    there is no folder named .a_hidden_folder_in_jane in jane

  • I make .a_hidden_folder_in_jane

    mkdir .a_hidden_folder_in_jane
    

    the terminal goes back to the command line

  • I try to change directory to .a_hidden_folder_in_jane again

    cd .a_hidden_folder_in_jane
    

    the terminal is my friend, and shows

    .../doe/jane/.a_hidden_folder_in_jane
    
  • I change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    cd: no such file or directory: jane
    
    • jane is not a child of .a_hidden_folder_in_jane

    • I cannot go from .a_hidden_folder_in_jane to jane this way

  • I go up a level to the parent of .a_hidden_folder_in_jane

    cd ..
    

    the terminal is my friend, and shows

    .../doe/jane
    

    I am back in jane

  • I use tree

    tree
    

    the terminal is my friend, and shows

    .
    └── mary
    
    2 directories, 0 files
    
    • I use tree with the -a option

      tree -a
      

      the terminal is my friend, and shows

      .
      ├── .a_hidden_folder_in_jane
      └── mary
      
      3 directories, 0 files
      
      • . is jane when I am in jane

      • the line in the tree that goes from . to mary shows I can go from jane right to mary

      • the line in the tree that goes from . to .a_hidden_folder_in_jane shows I can go from jane right to .a_hidden_folder_in_jane

    C:.
    ├── .a_hidden_folder_in_jane
    └── mary
    
  • I go up a level to the parent of jane

    cd ..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am back in doe


  • I change directory to john

    cd john
    

    the terminal is my friend, and shows

    .../pumping_python/doe/john
    

    john is a child of doe

  • I use ls to show what is in john

    ls
    

    the terminal goes back to the command line

    • I use ls with the short form of the --all option

      ls -a
      

      the terminal is my friend, and shows

      .  ..
      

    the terminal goes back to the command line

    john has no children

  • I use tree

    tree
    

    the terminal is my friend, and shows

    .
    
    0 directories, 0 files
    

    john has no children, yet

  • I change directory to lil

    cd lil
    

    the terminal is my friend, and shows

    cd: no such file or directory: lil
    

    john has no children

  • I use mkdir to make lil

    mkdir lil
    

    the terminal goes back to the command line

  • I try to change directory to lil again

    cd lil
    

    the terminal is my friend, and shows

    .../doe/john/lil
    
    • I am in the lil folder

    • lil is a child of john

    • john is a child of doe

  • I change directory to john

    cd john
    

    the terminal is my friend, and shows

    cd: no such file or directory: john
    
    • john is not a child of lil

    • I cannot go from lil to john this way

  • I go up a level to the parent of lil

    cd ..
    

    the terminal is my friend, and shows

    .../doe/john
    

    I am back in john

  • I change directory to a hidden folder in john

    cd .a_hidden_folder_in_john
    

    the terminal is my friend, and shows

    cd: no such file or directory:
        .a_hidden_folder_in_john
    

    there is no folder named .a_hidden_folder_in_john in john

  • I use mkdir to make .a_hidden_folder_in_john

    mkdir .a_hidden_folder_in_john
    

    the terminal goes back to the command line

  • I try to change directory to .a_hidden_folder_in_john again

    cd .a_hidden_folder_in_john
    

    the terminal is my friend, and shows

    .../doe/john/.a_hidden_folder_in_john
    
  • I change directory to john

    cd john
    

    the terminal is my friend, and shows

    cd: no such file or directory: john
    
    • john is not a child of .a_hidden_folder_in_john

    • I cannot go from .a_hidden_folder_in_john to john this way

  • I go up a level to the parent of .a_hidden_folder_in_john

    cd ..
    

    the terminal is my friend, and shows

    .../doe/john
    

    I am back in john

  • I use tree

    tree
    

    the terminal is my friend, and shows

    .
    └── lil
    
    2 directories, 0 files
    
    • I use tree with the -a option

      tree -a
      

      the terminal is my friend, and shows

      .
      ├── .a_hidden_folder_in_john
      └── lil
      
      3 directories, 0 files
      
      • . is john when I am in john

      • the line in the tree that goes from . to lil shows I can go from john right to lil

      • the line in the tree that goes from . to .a_hidden_folder_in_john shows I can go from john right to .a_hidden_folder_in_john

    C:.
    ├── .a_hidden_folder_in_john
    └── lil
    
  • I go up a level to the parent of john

    cd ..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am back in doe

  • I use tree to show the files and folders related to doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── jane
       └── mary
    └── john
        └── lil
    
    5 directories, 0 files
    
    • I use the -a option with tree

      tree -a
      

      the terminal is my friend, and shows

      .
      ├── .a_hidden_folder_in_doe
      ├── jane
         ├── .a_hidden_folder_in_jane
         └── mary
      └── john
          ├── .a_hidden_folder_in_john
          └── lil
      
      8 directories, 0 files
      
    C:.
    ├── .a_hidden_folder_in_doe
    ├── jane
       ├── .a_hidden_folder_in_jane
       └── mary
    └── john
        ├── .a_hidden_folder_in_john
        └── lil
    

    the lines show that

    • I can go from doe right to .a_hidden_folder_in_doe

    • I can go from doe right to jane

    • I can go from doe right to john

    • I can go from jane right to .a_hidden_folder_in_jane

    • I can go from jane right to mary

    • I can go from john right to .a_hidden_folder_in_john

    • I can go from john right to lil

I know how to look at directory relationships


how to make an empty file

I can use the touch or New-Item program to make empty files in a folder

  • I use touch to make an empty file in doe

    touch a_file_in_doe
    

    the terminal goes back to the command line

    on Windows without Windows Subsystem for Linux

    use New-Item in place of touch

    New-Item a_file_in_doe
    
  • I use touch to make an empty hidden file in doe

    touch .a_hidden_file_in_doe
    
  • I use ls to see what is in the folder

    ls
    

    the terminal is my friend, and shows

    a_file_in_doe  jane  john
    
  • I use ls with the -a option

    ls -a
    

    the terminal is my friend, and shows

    .
    ..
    a_file_in_doe
    .a_hidden_file_in_doe
    .a_hidden_folder_in_doe
    jane
    john
    
  • I use New-Item to make an empty file in doe

    New-Item a_file_in_doe
    

    the terminal goes back to the command line

  • I use New-Item to make an empty hidden file in doe

    New-Item .a_hidden_file_in_doe
    
  • I use ls to show what is in doe

    ls
    

    the terminal is my friend, and shows

    Mode            LastWriteTime   Length  Name
    ----            -------------   ------  ----
    d-----    MM/DD/YYYY HH:MM A/PM         .a_hidden_folder_in_doe
    d-----    MM/DD/YYYY HH:MM A/PM         jane
    d-----    MM/DD/YYYY HH:MM A/PM         john
    -a----    MM/DD/YYYY HH:MM A/PM      0  .a_hidden_file_in_doe
    -a----    MM/DD/YYYY HH:MM A/PM      0  a_file_in_doe
    

    the terminal does not show . and .. and always shows hidden folders and files on Windows without Windows Subsystem for Linux

  • I change directory to jane

    cd jane
    

    the terminal is my friend, and shows

    .../pumping_python/doe/jane
    
    • I use touch to make an empty file in jane

      touch aka_jane_doe
      

      the terminal goes back to the command line

    • I use touch to make an empty hidden file in jane

      touch .a_hidden_file_in_jane
      

      the terminal goes back to the command line

    • I use ls to show what is in jane

      ls -a
      

      the terminal is my friend, and shows

      .
      ..
      .a_hidden_file_in_jane
      .a_hidden_folder_in_jane
      aka_jane_doe
      mary
      
    • I use New-Item to make an empty file in jane

      New-Item aka_jane_doe
      

      the terminal goes back to the command line

    • I use New-Item to make an empty hidden file in jane

      New-Item .a_hidden_file_in_jane
      

      the terminal goes back to the command line

    • I use ls to show what is in jane

      ls
      

      the terminal is my friend, and shows

      Mode            LastWriteTime   Length  Name
      ----            -------------   ------  ----
      d-----    MM/DD/YYYY HH:MM A/PM         .a_hidden_folder_in_jane
      d-----    MM/DD/YYYY HH:MM A/PM         mary
      -a----    MM/DD/YYYY HH:MM A/PM      0  .a_hidden_file_in_jane
      -a----    MM/DD/YYYY HH:MM A/PM      0  aka_jane_doe
      

      the terminal does not show . and .. and always shows hidden folders and files on Windows without Windows Subsystem for Linux

  • I change directory to the parent of jane

    cd ..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am back in doe


  • I change directory to john

    cd john
    

    the terminal is my friend, and shows

    .../pumping_python/doe/john
    
    • I use touch to make an empty file in john

      touch aka_john_doe
      

      the terminal goes back to the command line

    • I use touch to make an empty hidden file in john

      touch .a_hidden_file_in_john
      

      the terminal goes back to the command line

    • I use ls to show what is in john

      ls -a
      

      the terminal is my friend, and shows

      .
      ..
      .a_hidden_file_in_john
      .a_hidden_folder_in_john
      aka_john_doe
      lil
      
    • I use New-Item to make an empty file in john

      New-Item aka_john_doe
      

      the terminal goes back to the command line

    • I use New-Item to make an empty hidden file in john

      New-Item .a_hidden_file_in_john
      

      the terminal goes back to the command line

    • I use ls to show what is in john

      ls
      

      the terminal is my friend, and shows

      Mode            LastWriteTime   Length  Name
      ----            -------------   ------  ----
      d-----    MM/DD/YYYY HH:MM A/PM         .a_hidden_folder_in_john
      d-----    MM/DD/YYYY HH:MM A/PM         lil
      -a----    MM/DD/YYYY HH:MM A/PM      0  .a_hidden_file_in_john
      -a----    MM/DD/YYYY HH:MM A/PM      0  aka_john_doe
      

      the terminal does not show . and .. and always shows hidden folders and files on Windows without Windows Subsystem for Linux

  • I change directory to the parent of john

    cd ..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am back in doe

  • I use tree to show the files and folders related to doe

    Tip

    Your terminal may use colors to show the difference between directories and files

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── jane
       ├── aka_jane_doe
       └── mary
    └── john
        ├── aka_john_doe
        └── lil
    
    5 directories, 3 files
    

    I use tree with the -a option

    tree -a
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── .a_hidden_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
       ├── .a_hidden_file_in_jane
       ├── .a_hidden_folder_in_jane
       ├── aka_jane_doe
       └── mary
    └── john
        ├── .a_hidden_file_in_john
        ├── .a_hidden_folder_in_john
        ├── aka_john_doe
        └── lil
    
    8 directories, 6 files
    
    tree
    

    the terminal is my friend, and shows

    C:.
    ├── .a_hidden_folder_in_doe
    ├── jane
       ├── .a_hidden_folder_in_jane
       └── mary
    └── john
        ├── .a_hidden_folder_in_john
        └── lil
    

    I use tree with the /F option to show files and folders

    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          ├── .a_hidden_folder_in_jane
       └── mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
            ├── .a_hidden_folder_in_john
        └── lil
    

I know how to make an empty file


how to use directory relationships

  • I try to change directory from doe to mary in one step

    cd mary
    

    the terminal is my friend, and shows

    cd: no such file or directory: mary
    
    • I use tree with the -d option to show only the directories

      tree -d
      

      the terminal is my friend, and shows

      .
      ├── jane
         └── mary
      └── john
          └── lil
      
      5 directories
      
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe\mary'
                  because it does not exist
    
    • I use tree to show only the directories

      tree
      

      the terminal is my friend, and shows

      C:.
      ├── .a_hidden_folder_in_doe
      ├── jane
         ├── .a_hidden_folder_in_jane
         └── mary
      └── john
          ├── .a_hidden_folder_in_john
          └── lil
      
    • there is no line from doe to mary because mary is not a child of doe

    • there is a line from jane to mary because mary is a child of jane

    • there is a line from doe to jane because jane is a child of doe

  • I can go from doe to jane to mary in one step with

    cd jane/mary
    

    the terminal is my friend, and shows

    .../doe/jane/mary
    

    I cannot go to mary without its parent. How do I get back to doe?

  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    • doe is not a child of mary

    • I cannot go from mary to doe this way

  • I can go from mary back to doe in one step with ..

    cd ../..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    I am back in doe

    • .. is for the parent of a directory

    • ../.. is for the parent of the parent, that is a grandparent. I can use as many as I need for each parent, for example ../../../.. is the great great grand parent

    • .. from mary is jane

    • .. from jane is doe


  • I try to change directory from doe to lil in one step

    cd lil
    

    the terminal is my friend, and shows

    cd: no such file or directory: lil
    
    • I use tree with the -d option to show only the directories

      tree -d
      

      the terminal is my friend, and shows

      .
      ├── jane
         └── mary
      └── john
          └── lil
      
      5 directories
      
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe\lil'
                  because it does not exist
    
    • I use tree to show only the directories

      tree
      

      the terminal is my friend, and shows

      C:.
      ├── .a_hidden_folder_in_doe
      ├── jane
         ├── .a_hidden_folder_in_jane
         └── mary
      └── john
          ├── .a_hidden_folder_in_john
          └── lil
      
    • there is no line from doe to lil because lil is not a child of doe

    • there is a line from john to lil because lil is a child of john

    • there is a line from doe to john because john is a child of doe

  • I can go from doe to john to lil in one step with

    cd john/lil
    

    the terminal is my friend, and shows

    .../doe/john/lil
    

    I cannot go to lil without its parent. How do I get back to doe?

  • I change directory to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    • doe is not a child of lil

    • I cannot go from lil to doe this way

  • I can go from lil back to doe in one step with ..

    cd ../..
    

    the terminal is my friend, and shows

    .../pumping_python/doe
    

    🎶 that will bring us back to …/doe a deer, a female deer…🎶

    • .. is for the parent of a directory

    • ../.. is for the parent of the parent

    • .. from lil is john

    • .. from john is doe

Note

  • I can go right to folders that are where I am

  • I can go right from parent to child

  • I can use the path/address of a folder to go to it

I know how to use directory relationships


how to use touch with directory relationships

  • I use tree to show the files and folders related to doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── jane
       ├── aka_jane_doe
       └── mary
    └── john
        ├── aka_john_doe
        └── lil
    
    5 directories, 3 files
    
    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          ├── .a_hidden_folder_in_jane
       └── mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
            ├── .a_hidden_folder_in_john
        └── lil
    
  • I change directory to mary

    cd jane/mary
    

    the terminal is my friend, and shows

    .../doe/jane/mary
    

    I am in mary

    • I use touch to make an empty file in mary

      touch aka_mary_jane_doe
      

      the terminal goes back to the command line

    • I use touch to make an empty hidden file in mary

      touch .a_hidden_file_in_mary
      

      the terminal goes back to the command line

    • I use New-Item to make an empty file in mary

      New-Item aka_mary_jane_doe
      

      the terminal goes back to the command line

    • I use New-Item to make an empty hidden file in mary

      New-Item .a_hidden_file_in_mary
      

      the terminal goes back to the command line

  • I use mkdir to make a hidden directory in mary

    mkdir .a_hidden_folder_in_mary
    

    the terminal goes back to the command line

  • I use ls to show what is in mary

    ls -a
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_mary
    .a_hidden_folder_in_mary
    aka_mary_jane_doe
    
    ls
    

    Tip

    I can also use dir

    the terminal is my friend, and shows

    Mode            LastWriteTime   Length  Name
    ----            -------------   ------  ----
    d-----    MM/DD/YYYY HH:MM A/PM         .a_hidden_folder_in_mary
    -a----    MM/DD/YYYY HH:MM A/PM      0  .a_hidden_file_in_mary
    -a----    MM/DD/YYYY HH:MM A/PM      0  aka_mary_jane_doe
    
  • I use cd to go back to the grandparent of mary

    cd ../..
    

    the terminal is my friend, and shows

    ...pumping_python/doe
    

    I am back in doe


  • I change directory to lil

    cd john/lil
    

    the terminal is my friend, and shows

    .../doe/john/lil
    

    I am in lil

    • I use touch to make an empty file in lil

      touch aka_lil_john_doe
      
    • I use touch to make an empty hidden file in lil

      touch .a_hidden_file_in_lil
      
    • I use New-Item to make an empty file in lil

      New-Item aka_lil_john_doe
      
    • I use New-Item to make an empty hidden file in lil

      New-Item .a_hidden_file_in_lil
      
  • I use mkdir to make a hidden directory in lil

    mkdir .a_hidden_folder_in_lil
    
  • I use ls to show what is in lil

    ls -a
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_lil
    .a_hidden_folder_in_lil
    aka_lil_john_doe
    
    ls
    

    Tip

    I can also use dir

    the terminal is my friend, and shows

    Mode            LastWriteTime   Length  Name
    ----            -------------   ------  ----
    d-----    MM/DD/YYYY HH:MM A/PM         .a_hidden_folder_in_lil
    -a----    MM/DD/YYYY HH:MM A/PM      0  .a_hidden_file_in_lil
    -a----    MM/DD/YYYY HH:MM A/PM      0  aka_lil_john_doe
    
  • I use cd to go back to the grandparent of lil

    cd ../..
    

    the terminal is my friend, and shows

    ...pumping_python/doe
    

    I am back in doe

  • I use tree to see what I have so far

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── jane
       ├── aka_jane_doe
       └── mary
           └── aka_mary_jane_doe
    └── john
        ├── aka_john_doe
        └── lil
            └── aka_lil_john_doe
    
    5 directories, 5 files
    

    I use tree with the -a option

    tree -a
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── .a_hidden_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
       ├── .a_hidden_file_in_jane
       ├── .a_hidden_folder_in_jane
       ├── aka_jane_doe
       └── mary
           ├── .a_hidden_file_in_mary
           ├── .a_hidden_folder_in_mary
           └── aka_mary_jane_doe
    └── john
        ├── .a_hidden_file_in_john
        ├── .a_hidden_folder_in_john
        ├── aka_john_doe
        └── lil
            ├── .a_hidden_file_in_lil
            ├── .a_hidden_folder_in_lil
            └── aka_lil_john_doe
    
    10 directories, 10 files
    
    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          ├── .a_hidden_folder_in_jane
       └── mary
              .a_hidden_file_in_mary
              aka_mary_jane_doe
                  └── .a_hidden_folder_in_mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
            ├── .a_hidden_folder_in_john
        └── lil
               .a_hidden_file_in_lil
               aka_lil_john_doe
                    └── .a_hidden_folder_in_lil
    

  • I use touch to make an empty file in jane from inside doe

    touch jane/child_of_doe
    

    the terminal goes back to the command line

  • I use touch to make an empty file in mary from inside doe

    touch jane/mary/grandchild_of_doe
    

    the terminal goes back to the command line

  • I use touch to make an empty file in john from inside doe

    touch john/child_of_doe
    

    the terminal goes back to the command line

  • I use touch to make an empty file in lil from inside doe

    touch john/lil/grandchild_of_doe
    

    the terminal goes back to the command line

  • I use New-Item to make an empty file in jane from inside doe

    New-Item jane/child_of_doe
    

    the terminal goes back to the command line

  • I use New-Item to make an empty file in mary from inside doe

    New-Item jane/mary/grandchild_of_doe
    

    the terminal goes back to the command line

  • I use New-Item to make an empty file in john from inside doe

    New-Item john/child_of_doe
    

    the terminal goes back to the command line

  • I use New-Item to make an empty file in lil from inside doe

    New-Item john/lil/grandchild_of_doe
    

    the terminal goes back to the command line

  • I use tree to show the files and folders related to doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── jane
       ├── aka_jane_doe
       ├── child_of_doe
       └── mary
           ├── aka_mary_jane_doe
           └── grandchild_of_doe
    └── john
        ├── aka_john_doe
        ├── child_of_doe
        └── lil
            ├── aka_lil_john_doe
            └── grandchild_of_doe
    
    5 directories, 9 files
    
    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          child_of_doe
          ├── .a_hidden_folder_in_jane
       └── mary
              .a_hidden_file_in_mary
              aka_mary_jane_doe
              grandchild_of_doe
                  └── .a_hidden_folder_in_mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
           child_of_doe
            ├── .a_hidden_folder_in_john
        └── lil
               .a_hidden_file_in_lil
               aka_lil_john_doe
               grandchild_of_doe
                    └── .a_hidden_folder_in_lil
    
  • I change directory to jane

    cd jane
    
    • I use touch to make an empty file in mary from inside jane

      touch mary/child_of_jane
      
    • I use touch to make an empty file in doe from inside jane

      touch ../aka_parent_of_jane
      
    • I use touch to make an empty file in john from inside jane

      touch ../john/aka_sibling_of_jane
      
      • .. is the parent of jane which is doe

      • john is a child of doe

    • I use touch to make an empty file in lil from inside jane

      touch ../john/lil/child_of_sibling_of_john
      
    • I use New-Item to make an empty file in mary from inside jane

      New-Item mary/child_of_jane
      
    • I use New-Item to make an empty file in doe from inside jane

      New-Item ../aka_parent_of_jane
      
    • I use New-Item to make an empty file in john from inside jane

      New-Item ../john/aka_sibling_of_jane
      
      • .. is the parent of jane which is doe

      • john is a child of doe

    • I use New-Item to make an empty file in lil from inside jane

      New-Item ../john/lil/child_of_sibling_of_john
      
    • .. is the parent of jane which is doe

    • john is a child of doe

    • lil is a child of john

    I made a mistake - child_of_sibling_of_john should be child_of_sibling_of_jane


how to rename a file or directory

I can use the mv program to move a file and rename it at the same time.

  • I change directory to lil

    cd ../john/lil
    
  • I use mv to change child_of_sibling_of_john to child_of_sibling_of_jane

    mv child_of_sibling_of_john \
    child_of_sibling_of_jane
    

    the terminal goes back to the command line

    Tip

    I can also rename the file with one line from inside jane without cd (it is a long line)

    mv ../john/lil/\
    child_of_sibling_of_john \
    ../john/lil/\
    child_of_sibling_of_jane
    

    \ is a symbol that tells the computer I want to break up the line after I hit the enter/return key on the keyboard

mv means move, it takes two arguments

mv source target
  • source is the path/address I want to move the original file or folder from

  • target is the path/address I want to move the original file or folder to

  • this allows me to rename a file or folder in one step, the other way would be to

    that is two steps too many, I leave that to the dancers, give me one step.

I know how to rename a file


  • I use cd to go back to the grandparent of lil

    cd ../..
    
  • I use tree to show the files and folders related to doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── aka_parent_of_jane
    ├── jane
       ├── aka_jane_doe
       ├── child_of_doe
       └── mary
           ├── aka_mary_jane_doe
           ├── child_of_jane
           └── grandchild_of_doe
    └── john
        ├── aka_john_doe
        ├── aka_sibling_of_jane
        ├── child_of_doe
        └── lil
            ├── aka_lil_john_doe
            ├── child_of_sibling_of_jane
            └── grandchild_of_doe
    
    5 directories, 13 files
    
    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       aka_parent_of_jane
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          child_of_doe
          ├── .a_hidden_folder_in_jane
       └── mary
              .a_hidden_file_in_mary
              aka_mary_jane_doe
              child_of_jane
              grandchild_of_doe
                  └── .a_hidden_folder_in_mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
           aka_sibling_of_jane
           child_of_doe
            ├── .a_hidden_folder_in_john
        └── lil
               .a_hidden_file_in_lil
               aka_lil_john_doe
               child_of_sibling_of_jane
               grandchild_of_doe
                    └── .a_hidden_folder_in_lil
    

  • I change directory to john

    cd john
    
    • I use touch to make an empty file in lil from inside john

      touch lil/child_of_john
      
    • I use touch to make an empty file in doe from inside john

      touch ../aka_parent_of_john
      
    • I use touch to make an empty file in jane from inside john

      touch ../jane/aka_sibling_of_john
      
      • .. is the parent of john which is doe

      • jane is a child of doe

    • I use touch to make an empty file in mary from inside john

      touch ../jane/mary/child_of_sibling_of_jane
      
    • I use New-Item to make an empty file in lil from inside john

      New-Item lil/child_of_john
      
    • I use New-Item to make an empty file in doe from inside john

      New-Item ../aka_parent_of_john
      
    • I use New-Item to make an empty file in jane from inside john

      New-Item ../jane/aka_sibling_of_john
      
      • .. is the parent of john which is doe

      • jane is a child of doe

    • I use New-Item to make an empty file in mary from inside john

      New-Item ../jane/mary/child_of_sibling_of_jane
      
    • .. is the parent of john which is doe

    • jane is a child of doe

    • mary is a child of jane

    I made a mistake again - child_of_sibling_of_jane should be child_of_sibling_of_john

  • I change directory to mary

    cd ../jane/mary
    
  • I use mv to change child_of_sibling_of_jane to child_of_sibling_of_john

    mv child_of_sibling_of_jane \
    child_of_sibling_of_john
    

    the terminal goes back to the command line

    Tip

    I can also rename the file with one line from inside john without cd (it is a long line)

    mv ../jane/mary/\
    child_of_sibling_of_jane \
    ../jane/mary/\
    child_of_sibling_of_john
    

    \ is the symbol that tells the computer I want to break up the line after I hit the enter/return key on the keyboard

  • I use cd to go back to the grandparent of lil

    cd ../..
    
  • I use tree to show the files and folders related to doe

    tree
    

    the terminal is my friend, and shows

    .
    ├── a_file_in_doe
    ├── aka_parent_of_jane
    ├── aka_parent_of_john
    ├── jane
       ├── aka_jane_doe
       ├── aka_sibling_of_john
       ├── child_of_doe
       └── mary
           ├── aka_mary_jane_doe
           ├── child_of_jane
           ├── child_of_sibling_of_john
           └── grandchild_of_doe
    └── john
        ├── aka_john_doe
        ├── aka_sibling_of_jane
        ├── child_of_doe
        └── lil
            ├── aka_lil_john_doe
            ├── child_of_john
            ├── child_of_sibling_of_jane
            └── grandchild_of_doe
    
    5 directories, 17 files
    
    tree /F
    

    the terminal is my friend, and shows

    C:.
       .a_hidden_file_in_doe
       aka_parent_of_jane
       aka_parent_of_john
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          aka_sibling_of_john
          child_of_doe
          ├── .a_hidden_folder_in_jane
       └── mary
              .a_hidden_file_in_mary
              aka_mary_jane_doe
              child_of_jane
              child_of_sibling_of_john
              grandchild_of_doe
                  └── .a_hidden_folder_in_mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
           aka_sibling_of_jane
           child_of_doe
            ├── .a_hidden_folder_in_john
        └── lil
               .a_hidden_file_in_lil
               aka_lil_john_doe
               child_of_john
               child_of_sibling_of_jane
               grandchild_of_doe
                    └── .a_hidden_folder_in_lil
    
  • I change directory to mary

    cd jane/mary
    
    • I use touch to make an empty file in jane from inside mary

      touch ../aka_parent_of_mary
      
    • I use touch to make an empty file in doe from inside mary

      touch ../../aka_grandparent_of_mary
      
    • I use touch to make an empty file in john from inside mary

      touch ../../john/aka_aunt_of_mary
      
    • I use New-Item to make an empty file in jane from inside mary

      New-Item ../aka_parent_of_mary
      
    • I use New-Item to make an empty file in doe from inside mary

      New-Item ../../aka_grandparent_of_mary
      
    • I use New-Item to make an empty file in john from inside mary

      New-Item ../../john/aka_aunt_of_mary
      

    I made a mistake - aka_aunt_of_mary should be aka_uncle_of_mary

  • I change directory to john

    cd ../../john
    
  • I use mv to change aka_aunt_of_mary to aka_uncle_of_mary

    mv aka_aunt_of_mary aka_uncle_of_mary
    
  • I change directory back to mary

    cd ../jane/mary
    
    • I use touch to make an empty file in lil from inside mary

      touch ../../john/lil/cousin_of_mary
      
    • I use New-Item to make an empty file in lil from inside mary

      New-Item ../../john/lil/cousin_of_mary
      
  • I use tree to show the files and folders related to doe from inside mary

    tree ../..
    

    the terminal is my friend, and shows

    ../..
    ├── a_file_in_doe
    ├── aka_grandparent_of_mary
    ├── aka_parent_of_jane
    ├── aka_parent_of_john
    ├── jane
       ├── aka_jane_doe
       ├── aka_parent_of_mary
       ├── aka_sibling_of_john
       ├── child_of_doe
       └── mary
           ├── aka_mary_jane_doe
           ├── child_of_jane
           ├── child_of_sibling_of_john
           └── grandchild_of_doe
    └── john
        ├── aka_john_doe
        ├── aka_sibling_of_jane
        ├── aka_uncle_of_mary
        ├── child_of_doe
        └── lil
            ├── aka_lil_john_doe
            ├── child_of_john
            ├── child_of_sibling_of_jane
            ├── cousin_of_mary
            └── grandchild_of_doe
    
    5 directories, 21 files
    
    tree ../.. /F
    

    the terminal is my friend, and shows

    C:.\...\PUMPING_PYTHON\DOE
       .a_hidden_file_in_doe
       aka_grandparent_of_mary
       aka_parent_of_jane
       aka_parent_of_john
       a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
          .a_hidden_file_in_jane
          aka_jane_doe
          aka_parent_of_mary
          aka_sibling_of_john
          child_of_doe
          ├── .a_hidden_folder_in_jane
       └── mary
              .a_hidden_file_in_mary
              aka_mary_jane_doe
              child_of_jane
              child_of_sibling_of_john
              grandchild_of_doe
                  └── .a_hidden_folder_in_mary
    └── john
           .a_hidden_file_in_john
           aka_john_doe
           aka_sibling_of_jane
           aka_uncle_of_mary
           child_of_doe
            ├── .a_hidden_folder_in_john
        └── lil
               .a_hidden_file_in_lil
               aka_lil_john_doe
               child_of_john
               child_of_sibling_of_jane
               cousin_of_mary
               grandchild_of_doe
                    └── .a_hidden_folder_in_lil
    
  • I change directory to lil from mary

    cd ../../john/lil
    

    the terminal is my friend, and shows

    .../doe/john/lil
    
    • I use touch to make an empty file in john from inside lil

      touch ../aka_parent_of_lil
      
    • I use touch to make an empty file in doe from inside lil

      touch ../../aka_grandparent_of_lil
      
    • I use touch to make an empty file in jane from inside lil

      touch ../../jane/aka_uncle_of_lil
      

      I made another mistake - aka_uncle_of_lil should be aka_aunt_of_lil

    • I use New-Item to make an empty file in john from inside lil

      New-Item ../aka_parent_of_lil
      
    • I use New-Item to make an empty file in doe from inside lil

      New-Item ../../aka_grandparent_of_lil
      
    • I use New-Item to make an empty file in jane from inside lil

      New-Item ../../jane/aka_uncle_of_lil
      

      I made another mistake - aka_uncle_of_lil should be aka_aunt_of_lil

  • I change directory to jane

    cd ../../jane
    
  • I use mv to change aka_uncle_of_lil to aka_aunt_of_lil

    mv aka_uncle_of_lil aka_aunt_of_lil
    
  • I change directory back to lil

    cd ../john/lil
    
    • I use touch to make an empty file in mary from inside lil

      touch ../../jane/mary/cousin_of_lil
      
    • I use New-Item to make an empty file in mary from inside lil

      New-Item ../../jane/mary/cousin_of_lil
      
  • I use tree to show the files and folders related to doe from inside lil through the parent of doe

    tree ../../../doe
    

    the terminal is my friend, and shows

    doe
    ├── a_file_in_doe
    ├── .a_hidden_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── aka_grandparent_of_lil
    ├── aka_grandparent_of_mary
    ├── aka_parent_of_jane
    ├── aka_parent_of_john
    ├── jane
       ├── .a_hidden_file_in_jane
       ├── .a_hidden_folder_in_jane
       ├── aka_aunt_of_lil
       ├── aka_jane_doe
       ├── aka_parent_of_mary
       ├── aka_sibling_of_john
       ├── child_of_doe
       └── mary
           ├── .a_hidden_file_in_mary
           ├── .a_hidden_folder_in_mary
           ├── aka_mary_jane_doe
           ├── child_of_jane
           ├── child_of_sibling_of_john
           ├── cousin_of_lil
           └── grandchild_of_doe
    └── john
        ├── .a_hidden_file_in_john
        ├── .a_hidden_folder_in_john
        ├── aka_john_doe
        ├── aka_parent_of_lil
        ├── aka_sibling_of_jane
        ├── aka_uncle_of_mary
        ├── child_of_doe
        └── lil
            ├── .a_hidden_file_in_lil
            ├── .a_hidden_folder_in_lil
            ├── aka_lil_john_doe
            ├── child_of_john
            ├── child_of_sibling_of_jane
            ├── cousin_of_mary
            └── grandchild_of_doe
    
    10 directories, 30 files
    
    tree ../../../doe /F
    

    the terminal is my friend, and shows

    C:.\...\PUMPING_PYTHON\DOE
    │   .a_hidden_file_in_doe
    │   aka_grandparent_of_lil
    │   aka_grandparent_of_mary
    │   aka_parent_of_jane
    │   aka_parent_of_john
    │   a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
    │   │   .a_hidden_file_in_jane
    │   │   aka_aunt_of_lil
    │   │   aka_jane_doe
    │   │   aka_parent_of_mary
    │   │   aka_sibling_of_john
    │   │   child_of_doe
    │   │
    │   ├── .a_hidden_folder_in_jane
    │   └── mary
    │       │   .a_hidden_file_in_mary
    │       │   aka_mary_jane_doe
    │       │   child_of_jane
    │       │   child_of_sibling_of_john
    │       │   cousin_of_lil
    │       │   grandchild_of_doe
    │       │
    │       └── .a_hidden_folder_in_mary
    └── john
        │   .a_hidden_file_in_john
        │   aka_john_doe
        │   aka_parent_of_lil
        │   aka_sibling_of_jane
        │   aka_uncle_of_mary
        │   child_of_doe
        ├── .a_hidden_folder_in_john
        └── lil
            │   .a_hidden_file_in_lil
            │   aka_lil_john_doe
            │   child_of_john
            │   child_of_sibling_of_jane
            │   cousin_of_mary
            │   grandchild_of_doe
            └── .a_hidden_folder_in_lil
    
    • .. is for the parent of lil which is john

    • ../.. is for the parent of the parent of lil which is doe

    • ../../.. is for the parent of the parent of the parent of lil which is pumping_python

    • doe is a child of pumping_python

I can add a file to any folder when I know its path or relation to where I am, if I have permission to write to the folder.

I know how to use touch with directory relationships


how to use ls with directory relationships

I can see what is in any folder when I know its path or relation to where I am.

  • I go to the parent of doe

    cd ../../..
    

    the terminal is my friend, and shows

    .../pumping_python
    

    I am in pumping_python

  • I use ls to show what is in doe

    ls -a doe
    
    ls doe
    

    Tip

    I can also use dir

    dir doe
    

    the terminal is my friend, and shows

    .
    ..
    a_file_in_doe
    .a_hidden_file_in_doe
    .a_hidden_folder_in_doe
    aka_grandparent_of_lil
    aka_grandparent_of_mary
    aka_parent_of_jane
    aka_parent_of_john
    jane
    john
    
  • I use ls to show what is in jane

    ls -a doe/jane
    
    ls doe/jane
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_jane
    .a_hidden_folder_in_jane
    aka_aunt_of_lil
    aka_jane_doe
    aka_parent_of_mary
    aka_sibling_of_john
    child_of_doe
    mary
    
  • I use ls to show what is in mary

    ls -a doe/jane/mary
    
    ls doe/jane/mary
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_mary
    .a_hidden_folder_in_mary
    aka_mary_jane_doe
    child_of_jane
    child_of_sibling_of_john
    cousin_of_lil
    grandchild_of_doe
    
  • I change directory to mary

    cd doe/jane/mary
    
  • I use ls to show what is in john from inside mary

    ls -a ../../john
    
    ls ../../john
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_john
    .a_hidden_folder_in_john
    aka_john_doe
    aka_parent_of_lil
    aka_sibling_of_jane
    aka_uncle_of_mary
    child_of_doe
    lil
    
  • I use ls to show what is in lil from inside mary

    ls -a ../../john/lil
    
    ls ../../john/lil
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_lil
    .a_hidden_folder_in_lil
    aka_lil_john_doe
    child_of_john
    child_of_sibling_of_jane
    cousin_of_mary
    grandchild_of_doe
    

I know how to use ls with directory relations


how to use tree with directory relationships

  • I use tree to show what is in lil

    tree ../../john/lil
    

    the terminal is my friend, and shows

    ../../john/lil
    ├── aka_lil_john_doe
    ├── child_of_john
    ├── child_of_sibling_of_jane
    ├── cousin_of_mary
    └── grandchild_of_doe
    
    1 directory, 5 files
    
    tree ../../john/lil /F
    

    the terminal is my friend, and shows

    C:\...\PUMPING_PYTHON\DOE\JOHN\LIL
    │   .a_hidden_file_in_lil
    │   aka_lil_john_doe
    │   child_of_john
    │   child_of_sibling_of_jane
    │   cousin_of_mary
    │   grandchild_of_doe
    └── .a_hidden_folder_in_lil
    
  • I use tree to show what is in john

    tree ../../john
    

    the terminal is my friend, and shows

    ../../john
    ├── aka_john_doe
    ├── aka_parent_of_lil
    ├── aka_sibling_of_jane
    ├── aka_uncle_of_mary
    ├── child_of_doe
    └── lil
        ├── aka_lil_john_doe
        ├── child_of_john
        ├── child_of_sibling_of_jane
        ├── cousin_of_mary
        └── grandchild_of_doe
    
    2 directories, 10 files
    
    tree /F ../../john
    

    the terminal is my friend, and shows

    C:\...\PUMPING_PYTHON\DOE\JOHN
    │   .a_hidden_file_in_john
    │   aka_john_doe
    │   aka_parent_of_lil
    │   aka_sibling_of_jane
    │   aka_uncle_of_mary
    │   child_of_doe
    ├── .a_hidden_folder_in_john
    └── lil
        │   .a_hidden_file_in_lil
        │   aka_lil_john_doe
        │   child_of_john
        │   child_of_sibling_of_jane
        │   cousin_of_mary
        │   grandchild_of_doe
        └── .a_hidden_folder_in_lil
    
  • I change directories from mary to lil

    cd ../../john/lil
    

    the terminal is my friend, and shows

    .../doe/john/lil
    

    I am in lil

  • I look at what is in mary from inside lil

    ls -a ../../jane/mary
    
    ls ../../jane/mary
    

    the terminal is my friend, and shows

    .
    ..
    .a_hidden_file_in_mary
    .a_hidden_folder_in_mary
    aka_mary_jane_doe
    child_of_jane
    child_of_sibling_of_john
    cousin_of_lil
    grandchild_of_doe
    
  • I use tree to show what is in mary

    tree ../../jane/mary
    

    the terminal is my friend, and shows

    ../../jane/mary
    ├── aka_mary_jane_doe
    ├── child_of_jane
    ├── child_of_sibling_of_john
    ├── cousin_of_lil
    └── grandchild_of_doe
    
    1 directory, 5 files
    
    tree ../../jane/mary /F
    

    the terminal is my friend, and shows

    C:\...\PUMPING_PYTHON\DOE\JANE\MARY
      │   .a_hidden_file_in_mary
      │   aka_mary_jane_doe
      │   child_of_jane
      │   child_of_sibling_of_john
      │   cousin_of_lil
      │   grandchild_of_doe
      └── .a_hidden_folder_in_mary
    
  • I use tree to show what is in jane

    tree ../../jane
    

    the terminal is my friend, and shows

    ../../jane
    ├── aka_aunt_of_lil
    ├── aka_jane_doe
    ├── aka_parent_of_mary
    ├── aka_sibling_of_john
    ├── child_of_doe
    └── mary
        ├── aka_mary_jane_doe
        ├── child_of_jane
        ├── child_of_sibling_of_john
        ├── cousin_of_lil
        └── grandchild_of_doe
    
    2 directories, 10 files
    
    tree /F ../../jane
    

    the terminal is my friend, and shows

    C:\...\PUMPING_PYTHON\DOE\JANE
      │   .a_hidden_file_in_jane
      │   aka_aunt_of_lil
      │   aka_jane_doe
      │   aka_parent_of_mary
      │   aka_sibling_of_john
      │   child_of_doe
      ├── .a_hidden_folder_in_jane
      └── mary
          │   .a_hidden_file_in_mary
          │   aka_mary_jane_doe
          │   child_of_jane
          │   child_of_sibling_of_john
          │   cousin_of_lil
          │   grandchild_of_doe
          └── .a_hidden_folder_in_mary
    
  • I go to the parent of doe

    cd ../../..
    

    the terminal is my friend, and shows

    .../pumping_python
    
  • I show all the doe family directories

    tree doe -ad
    

    the terminal is my friend, and shows

    doe
    ├── .a_hidden_folder_in_doe
    ├── jane
       ├── .a_hidden_folder_in_jane
       └── mary
           └── .a_hidden_folder_in_mary
    └── john
        ├── .a_hidden_folder_in_john
        └── lil
            └── .a_hidden_folder_in_lil
    
    10 directories
    
    tree doe
    

    the terminal is my friend, and shows

    C:\...\PUMPING_PYTHON\DOE
    ├── .a_hidden_folder_in_doe
    ├── jane
    │   ├── .a_hidden_folder_in_jane
    │   └── mary
    │       └── .a_hidden_folder_in_mary
    └── john
        ├── .a_hidden_folder_in_john
        └── lil
            └── .a_hidden_folder_in_lil
    
  • I show the relationships of files and folders in doe

    tree -a doe
    

    the terminal is my friend, and shows

    doe
    ├── a_file_in_doe
    ├── .a_hidden_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── aka_grandparent_of_lil
    ├── aka_grandparent_of_mary
    ├── aka_parent_of_jane
    ├── aka_parent_of_john
    ├── jane
       ├── .a_hidden_file_in_jane
       ├── .a_hidden_folder_in_jane
       ├── aka_aunt_of_lil
       ├── aka_jane_doe
       ├── aka_parent_of_mary
       ├── aka_sibling_of_john
       ├── child_of_doe
       └── mary
           ├── .a_hidden_file_in_mary
           ├── .a_hidden_folder_in_mary
           ├── aka_mary_jane_doe
           ├── child_of_jane
           ├── child_of_sibling_of_john
           ├── cousin_of_lil
           └── grandchild_of_doe
    └── john
        ├── .a_hidden_file_in_john
        ├── .a_hidden_folder_in_john
        ├── aka_john_doe
        ├── aka_parent_of_lil
        ├── aka_sibling_of_jane
        ├── aka_uncle_of_mary
        ├── child_of_doe
        └── lil
            ├── .a_hidden_file_in_lil
            ├── .a_hidden_folder_in_lil
            ├── aka_lil_john_doe
            ├── child_of_john
            ├── child_of_sibling_of_jane
            ├── cousin_of_mary
            └── grandchild_of_doe
    
    10 directories, 30 files
    
    • I show the path for each file and folder in doe with the -a and -f options

      tree -af doe
      

      the terminal is my friend, and shows

      doe
      ├── doe/a_file_in_doe
      ├── doe/.a_hidden_file_in_doe
      ├── doe/.a_hidden_folder_in_doe
      ├── doe/aka_grandparent_of_lil
      ├── doe/aka_grandparent_of_mary
      ├── doe/aka_parent_of_jane
      ├── doe/aka_parent_of_john
      ├── doe/jane
         ├── doe/jane/.a_hidden_file_in_jane
         ├── doe/jane/.a_hidden_folder_in_jane
         ├── doe/jane/aka_aunt_of_lil
         ├── doe/jane/aka_jane_doe
         ├── doe/jane/aka_parent_of_mary
         ├── doe/jane/aka_sibling_of_john
         ├── doe/jane/child_of_doe
         └── doe/jane/mary
             ├── doe/jane/mary/.a_hidden_file_in_mary
             ├── doe/jane/mary/.a_hidden_folder_in_mary
             ├── doe/jane/mary/aka_mary_jane_Doe
             ├── doe/jane/mary/child_Of_jane
             ├── doe/jane/mary/child_of_sibling_of_john
             ├── doe/jane/mary/cousin_of_lil
             └── doe/jane/mary/grandchild_of_doe
      └── doe/john
          ├── doe/john/.a_hidden_file_in_john
          ├── doe/john/.a_hidden_folder_in_john
          ├── doe/john/aka_john_doe
          ├── doe/john/aka_parent_of_lil
          ├── doe/john/aka_sibling_of_jane
          ├── doe/john/aka_uncle_of_mary
          ├── doe/john/child_of_doe
          └── doe/john/lil
              ├── doe/john/lil/.a_hidden_file_in_lil
              ├── doe/john/lil/.a_hidden_folder_in_lil
              ├── doe/john/lil/aka_lil_john_doe
              ├── doe/john/lil/child_of_john
              ├── doe/john/lil/child_of_sibling_of_jane
              ├── doe/john/lil/cousin_of_mary
              └── doe/john/lil/grandchild_of_doe
      
      10 directories, 30 files
      
    tree /F doe
    

    the terminal is my friend, and shows

    C:.\...\PUMPING_PYTHON\DOE
    │   .a_hidden_file_in_doe
    │   aka_grandparent_of_lil
    │   aka_grandparent_of_mary
    │   aka_parent_of_jane
    │   aka_parent_of_john
    │   a_file_in_doe
    ├── .a_hidden_folder_in_doe
    ├── jane
    │   │   .a_hidden_file_in_jane
    │   │   aka_aunt_of_lil
    │   │   aka_jane_doe
    │   │   aka_parent_of_mary
    │   │   aka_sibling_of_john
    │   │   child_of_doe
    │   │
    │   ├── .a_hidden_folder_in_jane
    │   └── mary
    │       │   .a_hidden_file_in_mary
    │       │   aka_mary_jane_doe
    │       │   child_of_jane
    │       │   child_of_sibling_of_john
    │       │   cousin_of_lil
    │       │   grandchild_of_doe
    │       │
    │       └── .a_hidden_folder_in_mary
    └── john
        │   .a_hidden_file_in_john
        │   aka_john_doe
        │   aka_parent_of_lil
        │   aka_sibling_of_jane
        │   aka_uncle_of_mary
        │   child_of_doe
        ├── .a_hidden_folder_in_john
        └── lil
            │   .a_hidden_file_in_lil
            │   aka_lil_john_doe
            │   child_of_john
            │   child_of_sibling_of_jane
            │   cousin_of_mary
            │   grandchild_of_doe
            └── .a_hidden_folder_in_lil
    

I can do things with files and folders in one step as long as

  • I know their paths/addresses

  • I know their relation to where I am and

  • I can write to them

It is easier to go where I want, if I know where I am.

I know how to use directory relationships


how to remove a directory and all the things in it

  • I try to remove doe and all its children and their children

    rm doe
    

    the terminal is my friend, and shows

    rm: cannot remove 'doe': Is a directory
    

    I cannot remove a directory this way

    • I remove doe and all its children and their children with the -r/--recursive option

      Danger

      This is a destructive operation that takes a lot of work and time to undo on MacOS or Linux/Windows Subsystem for Linux. Do you want to do it?

      rm --recursive doe
      

      the terminal goes back to the command line

      • rm means remove

      • --recursive or -r means remove child directories and what is in them until there is nothing left. It goes through every directory in the tree and removes everything

    Remove-Item doe
    

    the terminal is my friend, and shows

    Confirm
    The item at C:\...\pumping_python\doe has children
    and the Recurse parameter was not specified.
    If you continue, all children will be removed with the item.
    Are you sure you want to continue?
    [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend
    [?] Help (default is "Y"):
    

    I could use A on the keyboard to answer Yes to All or give one command to delete all the files and folders and ask me no questions.

    I use ctrl+c on the keyboard to go back to the command line then use Remove-Item with the -Recurse and -Force options

    Remove-Item doe -Recurse -Force
    
    • Remove-Item is used to remove files and folders

    • -Recurse means remove child directories and what is in them until there is nothing left. It goes through every directory in the tree and removes everything

    • -Force means do not ask me any questions, just remove the file or folder

  • I try to change directory back to doe

    cd doe
    

    the terminal is my friend, and shows

    cd: no such file or directory: doe
    
    Set-Location: Cannot find path
                  'C:\...\pumping_python\doe'
                  because it does not exist
    

    doe is gone!

review

I ran these commands to play with folders (directories)

How many questions do you think you can answer after going through this chapter?


code from the chapter

Do you want to see all the CODE I typed in this chapter?


what is next?

You know

Homework

use these commands - mkdir, cd, ls, tree and touch - to make your family tree. Send it to me when you are done.

Click Here to see me make a Python Test Driven Development Environment


rate pumping python

If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too