Command Line Practice
Here's a Cheat Sheet if you get stuck.
Episode X: A New Terminal
A long time ago in a Unix environment far, far away... young Jedi Padawans who knew only of desktop software were seduced by the dark side of the Force to enter:
The Terminal...
Setup
- Open the Terminal app
- In today's folder in the class repo, create a directory called called
star_wars.
Complete all work inside the star_wars folder.
Part I: Set the Scene
- Create a directory called
death_star, and make the following files inside of it:darth_vader.txt,princess_leia.txt,storm_trooper.txt - Make a
galaxy_far_far_awaydirectory. - Inside of
galaxy_far_far_away, make a directory namedtatooineand create the following files in it:luke.txt,ben_kenobi.txt. - Inside of
tatooinemake a directory calledmillenium_falcon, and in it createhan_solo.txtandchewbacca.txtfiles.
Part II: mv - rename
- You can rename a file using the
mvcommand. - Rename
ben_kenobi.txttoobi_wan.txt.
Part III: cp - copy
- You can copy a file from one location to another using the
cpcommand. (man cpfor more info) - Copy
storm_trooper.txtfromdeath_startotatooine.
Part IV: mv - move
- You can use the
mvcommand to move files from one location to another.mvcan be used for renaming, moving, or both. Runman mvto see the options—remember hit theQkey to get out of the manual page viewer. - Move
luke.txtandobi_wan.txtto themillenium_falcon. - Move
millenium_falconout oftatooineand intogalaxy_far_far_away. - Move
millenium_falconintodeath_star. - Move
princess_leia.txtinto themillenium_falcon.
Part V: rm - remove
BE CAREFUL WITH rm!!! THERE IS NO "TRASH" IN THE UNIX CLI. WHEN YOU DELETE SOMETHING IT IS GONE FOREVER!!!
You can use rm to delete a file.
- Delete
obi_wan.txt.
Part VI: All together
- In
galaxy_far_far_away, make a directory calledyavin_4. - Move the
millenium_falconout of thedeath_starand intoyavin_4. - Make a directory in
yavin_4calledx_wing. - Move
princess_leia.txttoyavin_4andluke.txttox_wing. - Move the
millenium_falconandx_wingout ofyavin_4and intogalaxy_far_far_away. - In
death_star, create directories fortie_fighter_1,tie_fighter_2andtie_fighter_3. - Move
darth_vader.txtintotie_fighter_1. - Make a copy of
storm_trooper.txtin bothtie_fighter_2andtie_fighter_3. - Move all of the
tie_fightersout of thedeath_starand intogalaxy_far_far_away.
Part VII: rm -r: Remove directories and everything they contain
BE CAREFUL WITH rm!!! THERE IS NO TRASH CAN IN THE UNIX CLI. WHEN YOU DELETE SOMETHING IT IS GONE FOREVER
Before you hit enter, make sure are deleting the right thing, or you could accidentally delete the contents of your computer (it has happened).
This command will not typically ask you if you "really want to delete." It will just delete.
- Remove
tie_fighter_2andtie_fighter_3.
Part VIII: May the Force Be With You..
- Touch a file in
x_wingcalledthe_force.txt. - Destroy the
death_starand anyone inside of it. - Return
x_wingand themillenium_falcontoyavin_4.