What are “man pages”?

man is the command used to access the on-line reference manual pages. Suppose you wish to read more about the passwd command. If you type man passwd at the prompt, the screen will soon fill with information about how the passwd command works. Quite often, you may receive more information than you bargained for. Obviously, this requires that you know the command name.

I don’t recall the exact command name. How can I find out?

If you do not know a command name, you can use apropos keyword, where keyword is a word that appears in the command description. For example, if you want to know what the pascal compiler is called, simply type apropos pascal, and you will see the following:

pc (1)        - Pascal compiler
tangle (1)    - translate WEB to Pascal

What other information is available?

  • The info command uses Emacs to give access to information on many GNU packages, such as GCC, CPP, DVIPS, ISPELL, and EMACS itself.

  • Google is your friend! There are many resources available online should you get stuck and need a refresher on terminal commands.

  • Last, but not least, there is often a kind fellow user sitting at the terminal next to you that you can ask for help.

How do I list my files?

The ls command lists the contents of the directory you are currently in. If you want to check what directory you are in, use the pwd command (which stands for “path of working directory”). Here’s an example:

pollard@lab1537-6% ls

Mail                 letters              staff
ams-submissions      misc                 sup-info
bin                  ncaraph.l            template.tex
elmrc                papers               z-modules
grades               setaccounts

There are many parameters to the ls command to display specific information about the files. You can read about these using the man command. One flag of particular use is the -F flag. This tells UNIX to list your files with some extra information. Here is what it looks like:

pollard@lab1537-6% ls -F

Mail/                letters/             staff/
ams-submissions/     misc/                sup-info
bin/                 ncaraph.l            template.tex
elmrc                papers/              z-modules
grades/              setaccounts*

Here you can easily see which files are subdirectories because they have a / after them. Executable files are marked with a * and symbolic links would be marked with a @.

How do I make or remove a directory?

mkdir dirname where dirname is the name of the directory you want to create. rmdir dirname to remove it.

How do I change directories?

The command cd is used to change directories. See the following example:

cd dirname
cd dirname/subdirname
cd .. # to go back one level
cd ~username/dirname
cd ~/dirname
cd # will go to your home directory

How do I create & delete files?

The rm command is used to remove (delete) files. It is very easy to use. Simply type rm filename where filename is the name of the file you want to delete. You may use wildcards (such as *) to operate on more than one file at a time. With rm this is very risky – you can easily delete additional files unintentionally.

How do I check and change file permissions?

If you do ls -l to get a “long” file listing, you will see a format like this:

-rw-r-----   1 ecke     grad        9384 May 24 09:29 faq.html
-rwxr-x---   1 ecke     grad       32194 May 22 08:00 a.out
drwxr-x---  13 ecke     grad        1024 May 23 16:36 public_html

It shows (from right to left) the name of the file or directory, then the time it was modified last, then group membership and name of the owner, some number and access permissions. The file faq.html has read and write access for the user (leftmost column), read access for members of the same group, and no access for all others. To grant read permission to other users, type chmod o+r faq.html. To remove read permission from group members (group grad in this case), use chmod g-r faq.html.

The next example is an executable, a.out. The x in the access permissions list indicates that it may be executed by the user and members of the same group. You may use chmod o=rx a.out to make it available to all users.

Finally, there is a directory, public_html, marked as such by the leading d in the access permissions list. Note that to be accessible, a directory must have both read and execute permissions.

How do I redirect command input/output?

In UNIX, you can tell a program that it should take its input from a file, rather than from the keyboard. For example the command ls > mylisting would take a listing of your files and directories and place them in a file called mylisting.

How to print a file from the command line?

If you know exactly which printer to send your file to, you can use the lpr command as follows:

lpr -P printer-name file-name

This will send the named file to the chosen printer.

How to check the print queue?

If you are curious to see if your job has been printed, or if you want to know if there is a long line for a particular printer, you can use the lpq -P printer-name command on Linux. You can request different types of printing status information using these commands

How to cancel a print job?

The easiest way to cancel a print job is to issue lprm job # on Linux.

You can be more specific and cancel a particular job by its request-ID, which is displayed after you submit the job:

pollard@lab1537-6$ lpr -P phaser1537-BW-pub testfile

    request id is phaser1537-BW-pub-425 (1 file(s))
    printout in room 1537

pollard@lab1537-6$ lprm phaser1537-BW-pub-425
    request "phaser1537-BW-pub-425" cancelled