Getting Started with Commands
==============================================================================
Overview: Now we dig into the heart of UNIX -- its commands. We discuss
what format these commands follow (such as how they specify
options), present a few of the simple commands, talk about the
on-line manual pages which give all the details on the commands,
and look at subsystem commands.
==============================================================================
Section Topics
------- ------
Shells
Formats of Commands
Simple Commands
The "man" pages
Complex commands and subsystems
Preview of commands
Shells
------
A shell is a program that runs on top of UNIX and interacts with you, the
user, in order to get things done. It allows you to type in commands and run
them in order to manipulate files, run programs, communicate via mail or
the Internet, and do anything else.
There are several shells in common use; you are not obligated to use just
one. The older shells are simpler and are meant to run on non-graphical
terminals. Newer shells emulate fancy graphical interfaces like the Macintosh
or Microsoft Windows. These are often called GUIs, or Graphical User
Interfaces.
The older shells support a command line style of interaction. First, the
shell prints a prompt telling you that it has finished the last command and
is waiting for you to enter the next command. After you type in a command and
hit RETURN, it takes what you typed in to be the command you want to run, which
it then runs, often displaying the output on the same terminal screen where you
typed the command.
If you use a GUI, like X Windows, you will often have several windows open
on your terminal screen. In each window you may be running an old fashioned
command line shell. Thus, it is still important that you understand how to use
these older shells.
The oldest shell, still in use, is called the Bourne shell, named after its
creator, S. R. Bourne. Its command name is "sh". A later shell was written
for the Berkeley version of UNIX, called the C-shell, named "csh". The C-shell
used a script language that (supposedly) looks more like the C programming
language than the Bourne shell's language. When you log on to the UNIX system
at Canisius you enter the csh shell by default.
Other shells came along such as the Korn shell, but none of these are as
widespread as the Bourne Shell and the C-shell. We will largely focus on the
C-shell here at Canisius.
Formats of Commands
-------------------
Every command in the shell starts off with the command's name. The name
must be spelled correctly and cannot be abbreviated. But since most commands
have very short names, this is not a big deal. UNIX is also case sensitive,
so "cp" is NOT the same as "Cp".
What follows the command name is largely up to the command. This lack of
standard format is a valid criticism of UNIX. However, a de facto standard has
evolved:
command options words
The options usually (but not always) begin with dashes. Sometimes they consist
of a single letter following the dash or there may be separate words.
The "words" above are often filenames, but may be something else like a
number, a username, or a directory name, all depending upon the specific
command.
Here are some examples of commands with options or other words:
ls -l
ls -l /
cat -n bigfile
cal 5 1996
vi +/anyword report
tail +100 anyfile
mail meyer schnirel fazio
mail -f
cc main.c -lm
Simple Commands
---------------
There are many simple but important commands in UNIX. For example,
who tells you who is currently logged on:
% who
There is also a date command for finding out the time and date:
% date
To see the calendar for the current month, use "cal":
% cal
If you want to see the calendar for the entire year, type that in after the
name. Notice that in this case, 1994 is not treated as a file name, nor an
option.
% cal 1994
You can also see the calendar for a specific month out of a specific year.
To do this, use the numerical name of the month, followed by the year:
% cal 5 1966
This prints out the month of May for 1966. Make sure that you do not
abbreviate the year. 66 is the year 66, when Nero was alive, not 1966.
The cal command also includes some anomalies that are part of our heritage.
Try printing out September, 1752. Why is this month so unusual? Cal's
output is NOT incorrect! (What happened is that England switched to the
Gregorian Calendar that month in order to correct the accumulated errors of
the older Julian calendar, and subsequently they had to skip ahead two
weeks to "catch up" with the Sun.)
$$$
As an example of a command that has more traditional options, the "ls"
command is good to study. This command "lists" filenames in a directory.
That is, it prints out the names of the files in the directory.
In the simplest form, "ls" without any options or filenames lists the
files in the current directory:
% ls
To list the files in a specific directory, give the name of the directory:
% ls /usr1
(Directories will be explained in more detail later.)
"ls" can also be used to tell if a file exists or not. Just enter the file's
name, and if it exists, UNIX will print back the file's name. If it doesn't
exist, UNIX says "filename not found".
There are many options for the "ls" command, and all of them begin with a
dash. One such option is -l, which prints the listing of file names along with
a great deal more information about each file, such as how big it is, when it
was last accessed, who owns it, and what the protections are.
% ls -l
Using -l, the files in the current directory are listed as follows:
drwx------ 4 doc 512 Jun 3 13:57 .dit.versions/
drwxr-xr-x 4 doc 512 May 7 08:48 C++/
drwxr-xr-x 6 doc 1536 Mar 29 13:27 CPGMS/
drwxr-xr-x 2 doc 512 May 27 09:44 CSC230/
drwxr-xr-x 4 doc 512 Apr 10 19:21 FP/
drwxr-xr-x 2 doc 512 May 6 1993 HOWTO/
drwxr-xr-x 10 doc 512 Jun 6 21:50 LESSONS/
-rw-r--r-- 1 doc 35478 Sep 9 1993 commands.file
-rw-r--r-- 1 doc 4525 May 27 10:10 commands1.menu
-rw-r--r-- 1 doc 2688 May 27 10:10 commands2.menu
-rw-r--r-- 1 doc 18550 Aug 29 1993 ethics.file
-rw-r--r-- 1 doc 9543 Sep 7 1993 glossary.file
-rw-r--r-- 1 doc 4035 Jun 3 14:21 intro
The exact output will be explained later in the "directories" tutorial.
The "man" pages
---------------
Another highly touted innovation of UNIX is the on-line UNIX manual,
called collectively "man pages". These are manual pages, arranged by command,
giving all the options, format of the commands, description of bugs and
associated files as well as a general discussion on what the command does.
Unfortunately, you have to know what the commands are before you use them.
For example, you have to know that there is a command called "rm" and that it
is generally used to delete a file. Once you know this, you can call up the
man page to figure out how to use it.
% man rm
Because new users do not even know the names of the UNIX commands, "man" is
not very friendly, and the on-line manual pages are not terribly readable.
This is why this help system was developed. However, the man pages are still
the final and definitive word on the commands, so you should know that they
exist and how to use them.
Complex commands and subsystems
-------------------------------
Several UNIX commands are very complex, such as mail. They even have
their own shell with their own prompt and their own subcommands. When you
start up one of these commands, you start up the whole subsystem and in order
to leave it gracefully you have to use its own quit or exit command. Your
regular UNIX shell will still be there, as if it were put to sleep temporarily
and then awakened when you exit the subsystem.
Here are some of the more common "subsystem" commands:
mail -- read and send electronic mail
readnews -- read the USENET bulletin boards
telnet -- remotely log in to other computers
ftp -- transfer files between computers
less -- displays a file one page at a time
Preview of commands
-------------------
In order to speed up your acquisition of elementary UNIX knowledge, here
are some commands that you will likely run into, categorized by their main
function.
Files: creating, copying, displaying, renaming, changing protections,
editing (changing), sorting, moving around, listing, finding
size of, destroying, searching
cat -- either displaying contents or creating
cp -- copying
mv -- renaming or moving to a different directory
rm -- destroying (deleting, removing)
chmod -- changing protection
wc -- analyzing size of (in terms of lines, words, bytes)
less -- viewing, browsing, searching
more -- (almost same as "less")
vi -- editing (changing or creating) (see also "ed")
sort -- sort a file; merge several files together
cmp -- compare two files (also see "diff" and "comm")
ln -- link a file (give it another name but do not make an
actual physical copy)
file -- describe the file's contents
grep -- search for character strings in a file
spell -- list the misspelled words in a file
look -- look up spelling of a word
df -- show how much disk space is used up on entire system
lpr -- print a file
head -- look at the first part of a file
tail -- look at the last part of a file
tr -- translate characters in a file
strings -- strip out all the nonprintable characters
nroff, troff -- word processor
Communication with other users:
mail -- electronic mail
write -- send a quick, one-line message
talk -- engage in a "chat" session with split screen text writing
who -- list usernames who are currently logged on
finger -- find out plan, project and last logon time of users
w -- show what command each user is currently executing
uptime -- show the load on the system (how busy it is)
Directories
ls -- list all the files in the current directory
cd -- change current directory
mkdir -- make a new directory
rmdir -- remove a directory (only if empty)
pwd -- print working directory, show where we currently are
pushd -- temporarily go to another directory
popd -- return to the last directory from which we pushd'ed
find -- walk through the directory tree trying to find a file
Compilers
cc -- C language
gcc -- GNU C compiler, accepts ANSI C, newer, nicer and faster!
g++ -- C++ compiler
CC -- the old AT&T C++ compiler
as -- assembler (for Sparc assembly language)
pc -- Pascal language
adacomp -- Ada (using the NYU ada system)
ibcl -- LISP (Ibuki Common LISP)
lint -- the C lint checker (not really a compiler, but it catches
many errors)
make -- not really a compiler, but it can compile a whole directory
adacomp, adabind, adaexec, adalib -- Ada educational system
Advanced File Manipulations
tar -- bundle together an entire directory in an archive file
ar -- create a program archive
compress -- squeeze down the size of a file to save disk space
uncompress -- unsqueeze the file
uuencode -- encode a file so that it can be mailed (changes all
nonprintable characters to a printable code)
uudecode -- opposite of uuencode
sed -- stream editor, make changes to every line in a file
Terminal and Miscellaneous
clear -- erase everything on the terminal screen
stty -- change terminal characteristics
date -- print out the current date and time
cal -- print out the calendar
time -- time a command, find out how long it takes to execute
echo -- echo print arguments of command back to terminal
whoami -- print out the username of the currently logged on user
at this terminal
fortune -- print out a fortune cookie saying
hostname -- tell what name of the computer is
man -- consult the on-line manual about a command or topic
yppasswd -- change your password