Class: SEI
Creator: Thom Page
Modified by: Kristyn Bryan and Reuben Ayres
Topics: Terminal, boolean expressions, reading code, while loops, for loops
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.
Follow the instructions below using all the console commands introduced in Fundamentals, class, or that you find on your own.
-
Open the Terminal app
-
Create a new directory in your
sei/fundamentalsdirectory calledstar_wars. -
Create a file called
commands.txt. -
Paste the answer to each numbered question (i.e. the command(s) that accomplished the task) in
commands.txtonce you get it to work. -
Remember, you can learn about any Unix command by typing
manand then the command name. E.g.,man ls. TypeQto get out of the Manual page ("man page") viewer.
Complete all work inside the star_wars folder.
-
Create a directory called
death_star, and make the following files inside of it:darth_vader.txt,princess_leia.txt,storm_trooper.txt -
In a directory
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 create:han_solo.txt,chewbaca.txt
- You can rename a file using the
mvcommand.
- Rename
ben_kenobi.txttoobi_wan.txt.
- You can copy a file from one location to another using the
cpcommand. (man cpfor more info)
- Directories can be sibling (parrell to each other) or can be parents (the folder that contains the folder you are in)
- Copy
storm_trooper.txtfromdeath_startotatooine.
- 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.
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.
-
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.
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.
-
Touch a file in
x_wingcalledthe_force.txt. -
Destroy the
death_starand anyone inside of it. -
Return
x_wingand themillenium_falcontoyavin_4.
"Add" your changes (prepare them to be "committed"):
$ git add -A"Commit" your changes—any time you make a commit, you can always restore the files in the repo to that point:
$ git commit -m "Completed homework assignment""Push" your commits to github:
$ git push origin masterWant an extra challenge? In many assignments or labs, you'll find a "Hungry for More" section which is designed for further learning. If they seem too overwhelming you can absolutely skip them. They won't factor into your homework score, and you will be totally fine for class as long as you complete and understand the main assignment up to that point. What they will do is encourage you to go deeper, explore, and push yourself. And that will pay off big time in the long run. Below is the "hungry for more" section for this assignment.
...as long as you don't mess up the homework assignment you just did. They get more difficult/complex as you go (more or less).
-
Create a directory called
test-dirwith a couple files in it. Try to make a copy of that entire directory. (Hint:man cpfor more info.) -
Find and use command line shortcuts.
-
Try applying one command to multiple files at once.
-
Try applying one command to all files in a single directory (where necessery)
-
Try applying one command to all files that match a pattern.
-
Try using a mix of absolute and relative paths.
-
If you're a glutton for punishment, read about the famous text editor "vi" online. It's included with all Unix systems, and although it has a steep learning curve, it is an incredibly powerful text editor. You can run a tutorial program that will teach you some
vi/vimcommands by typingvimtutorin your Terminal. See if you can use it to create and edit a small "Hello, World!" JavaScript program!
When you've got your homework all done, just send a Slack message to your instructor. Going forward, we will be submitting homework using a "pull request" process in git. Your instructor will show you the submission process tomorrow afternoon.