Anatomy of a Command#
Commands on this page:
Command |
Action |
---|---|
|
Securely connect to a shell on a remote machine over the internet |
|
Display a calendar |
|
Show free space on disk |
|
Show available RAM memory |
|
Exit the shell |
|
Show OS information |
|
Show Linux distribution information |
The Anatomy of a Command#
Commands are words separated by spaces. The first word is the name of the command. Subsequent words are called arguments. A special kind of argument called a switch or flag begins with the dash (-
) character.
Here’s an example of a simple command with no arguments:
$ cal
The cal
command shows a calendar of the current month. Many UNIX commands take the -h
or --help
switch as an argument. See what happens to the date
command when you add the -h
option.
$ cal -h
The cal
command will show you any month or year you like. With one argument, a year, cal
prints every month in that year:
$ cal 1976
Run the command above but substitute the year you were born. What day were you born on? Commands can take any number of arguments. You can add a month to the cal
command to print only a particular month in a year. This example prints the calendar for January 2030:
$ cal 01 2030
The -l
switch means long listing. In long form the ls
command prints one file per line with a bunch of extra information that we’ll talk about in the next lesson. The ls
command color codes its output. Directories are colored blue in the example above.
Directories contain both files and other directories. The tree
commands shows the structure of the current directory.
Run the tree
command and look at the output. You should see output very similar to mine.
The Terminal and the Shell#
The terminal is the program you use on your computer to view the command line. The terminal is software that takes the place of the old-school terminal hardware like the thing pictured below:
When the terminal is a program it’s called a terminal emulator but since it’s been so long since anyone has seen a real terminal everyone just says terminal. The shell is the program that shows you the prompt and accepts commands. The shell runs on the remote side of a network connection. When you use the ssh
command to access another computer the terminal runs on your computer and the shell is started by ssh
after you enter your login credentials.
The Current Directory#
There’s no place like home!
Runningcd
with no arguments takes you to your home directory.
When you use the file tool on your operating system the graphics on the screen show you files and folders at the same time and you pick what you want. On the command line you navigate folders by “walking” from one directory to another. The key concept that you have to remember is that of the working directory
. That’s the folder you’re working in. Think of it like the place you’re standing.
To help you understand the place you are standing let’s play a game from my childhood: Beyond Zork: The Coconut of Quendor
In the game you walk from place to place. The graphic on the screen helps you see the effect of moving in different directions. When you use the command line the cd
command moves you from place to place, the ls
command shows you what’s around and the pwd
command shows you where you are.
Arguments and File Names#
The Secure Shell (ssh
) command connects your terminal to another computer. When your terminal is connected the commands you issue will be run on the remote machine. The exit
command ends the connection. The ssh
command works on Windows (10 and above), Mac and Linux. The ssh
command works like this:
$ ssh <user-name>@<computer-name>
For example, this command logs me into opus.
$ ssh mmatera@opus.cis.cabrillo.edu