Guide - Command Line
Getting Started with Linux
You should be familiar with the Linux command line, a useful skill not only useful for CS 225 but also for many other courses and a lot of power uses of operating systems.
If you’re on an EWS machine, you can find the Terminal app by navigating
to Applications > System Tools > Terminal
located at the top of your screen.
(You can also drag this icon to the menu bar at the top of the screen for the future.)
Finally, if you navigate to a folder using Places and right-click inside it
there is an option Open In Terminal which will open the terminal. The Terminal app
is the command line interface for Linux, where you run programs by typing their
names, and sometimes parameters such as files to open, instead of clicking on
icons and buttons.
Command Line Tutorial
Type
pwd
and press enter. You’ll see the folder you are currently located in, called the working directory. Since you haven’t moved anywhere yet, this is your home directory.
Later on we’ll make a directory (folder) to store your coursework in, but for now, let’s create a test directory. Type the following in the terminal:
mkdir cs225test
Now let’s look at the contents of the folder we’re in (still your home directory):
ls
You’ll probably see several folders (in blue). One of these should be cs225test/
.
Let’s open cs225test/
:
cd cs225test/
If you type pwd
again, you will see you are now in cs225test/
inside of your
home directory. Finally, let’s get back to your home directory. Run one of:
cd ..
cd
cd ~
cd -
All of them will return you to your home directory. The first (cd ..
)
navigates to the parent of the current working directory. The second is a
shortcut builtin to cd
: running cd
without any parameters will navigate to
your home directory. The third (cd ~
) uses the ~
(a tilde), which is a
standard way to say “the home directory of the current user”. The fourth (cd -
) uses the -
(a dash), which allows the user to cd
into the directory that they previously were from. For example if pwd
returned ~/Documents
and you were to run cd ~/cs225test
, running cd -
once would go back to ~/Documents
and running cd -
again would take you back to ~/cs225test
Useful Linux commands cheat sheet:
pwd # Print Working Directory - shows the folder you are currently in
ls # List - lists the files in your current folder
cd FOLDER # Change Directory to FOLDER - opens FOLDER
cd .. # - opens the parent folder of your current location
cd # - opens your home folder
atom FILE & # Opens (or creates) FILE in atom, a text editor
gedit FILE & # Opens (or creates) FILE in gedit, a simple text editor
vim FILE # Opens (or creates) FILE in vim, a simple modal text editor
rm FILE # Remove - deletes FILE
rm -r FOLDER # - deletes a folder and its contents
mv SRC DEST # Move - moves/renames SRC to DEST
cp SRC DEST # Copy - copies SRC to DEST
make PROGRAM # Compiles PROGRAM using the rules in the Makefile file
xdg-open IMAGE # Opens IMAGE in the default image viewer
clear # Clear the terminal screen (Ctrl-l also works)
reset # Reset and clear the terminal
Keyboard Shortcuts for Bash:
Ctrl + a : Navigates to the beginning of the line
Ctrl + e : Navigates to the end of the line
Alt + b : Back (left) one word
Alt + f : Forward (right) one word
Ctrl + u : Clears the line from the cursor to the beginning
Ctrl + c : Kills the current command being executed (useful if run into an infinite loop)
tab : Attempts to autocomplete a command or file
More commands can be found here. Note that some of these commands may be unavailable for Mac OS X.
Check out the list above for useful Linux commands, and try using them. You can learn more by looking at the tutorials posted on the [Resources][resources] page.