CP367: Lab 02 - Winter 2026 - unix Commands I

Due 11:59 PM, Friday, January 23, 2026

Getting Help at the unix Command Line

A vitally important thing to know on any interface is how to get help. Know what the various unix system commands are is the first step, getting help with the commands is the second.

man command

man (manual) displays information (format, usage, examples) about the command command. It displays a preformatted page of information about command , including the sections NAME, SYNOPSIS, DESCRIPTION, OPERANDS, USAGE, and EXAMPLES. The information displayed are referred to as man pages. Even man has man pages. Type man man at the command line:

The man Page
	
MAN(1)                              Manual pager utils                             MAN(1)

NAME
       man - an interface to the on-line reference manuals

SYNOPSIS
       man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m sys‐
       tem[,...]]  [-M  path]  [-S  list]  [-e  extension]  [-i|-I]  [--regex|--wildcard]
       [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding]
       [--no-hyphenation]   [--no-justification]   [-p    string]    [-t]    [-T[device]]
       [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man  -l  [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P
       pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]]  [-H[browser]]
       [-X[dpi]] [-Z] file ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-?V]

DESCRIPTION
       man  is the system's manual pager. Each page argument given to man is normally the
       name of a program, utility or function.  The manual page associated with  each  of
       these  arguments  is then found and displayed. A section, if provided, will direct
       man to look only in that section of the manual.  The default action is  to  search
       in  all  of the available sections, following a pre-defined order and to show only
       the first page found, even if page exists in several sections.
 Manual page man(1) line 1 (press h for help or q to quit)

man pages can be quite long and complex: we recommend that the SYNOPSIS and EXAMPLES sections are particularly useful.

Command Line Options

unix command line options are often prefixed with a - or a -- . A common way to get help for a command is to use the -? or --help options when executing a command. These two options are often, though not always, synonyms - i.e. none, one, or both may exist for a given command. Append the command with | more to have the command display only one screen at a time.

The man command illustrates this usage by showing a quick synopsis of its options:

man -? | more
	
/home/dbrown> man -? | more
Usage: man [OPTION...] [SECTION] PAGE...

  -C, --config-file=FILE     use this user configuration file
  -d, --debug                emit debugging messages
  -D, --default              reset all options to their default values
      --warnings[=WARNINGS]  enable warnings from groff

 Main modes of operation:
  -f, --whatis               equivalent to whatis
  -k, --apropos              equivalent to apropos
  -K, --global-apropos       search for text in all pages
  -l, --local-file           interpret PAGE argument(s) as local filename(s)
  -w, --where, --path, --location
                             print physical location of man page(s)
  -W, --where-cat, --location-cat
                             print physical location of cat file(s)
--More--                      

The ls (list) command, on the other hand, does not support the -? option, but it does make a suggestion when an unknown option is entered:

ls -?
/home/dbrown> ls -?
ls: invalid option -- '?'
Try 'ls --help' for more information.
/home/dbrown> ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
...                               

Commands that are not on the current execution path or just wrong display an error:

Unknown Command
/home/dbrown> whatever
bash: whatever: command not found...
References

Nothing beats a good tutorial. There are literally hundreds available on the internet (Google is your friend). A good reference book can also come in handy. See Resources for a few of these.

Our CP367 labs concentrate on what you need to know for this course.


bash Shell Options

The bash shell has a number of different options that you will find very useful. It is difficult to show 'pictures' of them in action - try them.

Command Line History

The bash shell records the commands you have issued during this or previous sessions in the file .bash_history . You may scroll up and down through previously-issued commands by pressing the up and down arrow keys. Press Enter to execute the current listed command.

Command Line Auto-completion

The bash shell can auto-complete file references when you press the Tab key. For example, assume you wish to move a file into the CP367 directory. Enter the command:

mv file C<tab>

and the shell will auto-complete the directory name to CP367 by adding P367 to the end of the line.

If there is any ambiguity in a name - ex. more than one file or directory starts with ' C ', the shell displays a list of options. In the following example, the user starts by typing the command gcc -g -o ctest c , and then presses tab multiple times to see the options available:

Command Line Completion
/home/dbrown> gcc -g -o ctest C<tab>
gives:
/home/dbrown> gcc -g -o ctest CP367/<tab>
gives:
/home/dbrown> gcc -g -o ctest CP367/ctest<tab><tab>
gives:
ctest    ctest.c
/home/dbrown> gcc -g -o ctest CP367/ctest.c
gives:
/home/dbrown>
						

Some Basic Commands

This is but a brief list of typical unix commands and some useful options. For more details on any command, use man or Google.

more

This command displays the contents of a file one screen at a time. Typical usage:

						more ctest.c
					

Even if you do not use this command much to look at files - the emacs editor does that just fine - it is used to display man pages, and it is therefore important to understand how to navigate through a document with more . While inside a man page, press the spacebar to get the next page, or h to get a list of more options:

man ls
LS(1)                              User Commands                             LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information about the FILEs (the current directory by default).  Sort
       entries alphabetically if none of -cftuvSUX nor --sort is specified.

 Manual page ls(1) line 1 (press h for help or q to quit)

Now press h to bring up further help:

Further Help
                   SUMMARY OF LESS COMMANDS

      Commands marked with * may be preceded by a number, N.
      Notes in parentheses indicate the behavior if N is given.
      A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.

  h  H                 Display this help.
  q  :q  Q  :Q  ZZ     Exit.
 ---------------------------------------------------------------------------

                           MOVING

  e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
  y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
  f  ^F  ^V  SPACE  *  Forward  one window (or N lines).
  b  ^B  ESC-v      *  Backward one window (or N lines).
  z                 *  Forward  one window (and set window to N).
  w                 *  Backward one window (and set window to N).
  ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
...
 ---------------------------------------------------------------------------

                          SEARCHING

  /pattern          *  Search forward for (N-th) matching line.
  ?pattern          *  Search backward for (N-th) matching line.
HELP -- Press RETURN for more, or q when done

Thus, to go back a screen in a man page, press b . To find the EXAMPLES section without having to scroll through screen after screen, type /EXAMPLES .

ls

This command (list) displays the names and attributes of directories and files within a directory. Its simplest form is a list of names:

ls
/home/dbrown> ls CP367
#ctest.c#     dbrown.zip  ctest.c       heat.c
a1            ctest         heat          heat.c~

With the -l (long list) and -a (all entries) options, you get a more detailed list of files.

ls -la
/home/dbrown> ls -la CP367
total 64
-rw-------   1 dbrown ad_user      230 Jan  8 20:14 #ctest.c#
drwx------   3 dbrown ad_user      512 Jan 12 16:21 .
drwxr-xr-x   5 dbrown ad_user      512 Jan 12 16:23 ..
drwx------   2 dbrown ad_user      512 Jan 12 16:21 a1
-rw-------   1 dbrown ad_user     8605 Jan 12 16:21 dbrown.zip
-rwx------   1 dbrown ad_user     7332 Jan 16 10:58 ctest
-rw-------   1 dbrown ad_user      230 Jan  3 23:36 ctest.c
-rwx------   1 dbrown ad_user     7832 Jan  8 20:09 heat
-rw-------   1 dbrown ad_user      768 Jan  8 20:14 heat.c
-rw-------   1 dbrown ad_user      767 Jan  8 20:04 heat.c~

Without a parameter, ls displays the contents of the current directory. Note that you can sometimes concatenate options together with a single hyphen.

mv

The mv (move) command moves and renames files and directories. If no directory name is involved, then a file is simply renamed. Ex: rename the file test.c to oldtest.c :

						mv test.c oldtest.c
					

Ex: move the file test.c to the CP367 directory (the directory must already exist):

						mv test.c CP367/
					

Ex: move the file test.c to the CP367 directory and rename it to oldtest.c when it gets there:

						mv test.c CP367/oldtest.c
					

WARNING: unix does not warn you when you are about to overwrite or erase files. It just does exactly what you tell it to do. Be very cautious!

cp

The cp (copy) command copies files and directories. If no directory name is involved, then a file is copied in the same directory. Ex: copy the file test.c to test_2.c :

						cp test.c test_2.c
					

Ex: copy the file test.c to the CP367 directory (the directory must already exist):

						cp test.c CP367/
					

Ex: copy the file test.c to the CP367 directory and name it test_2.c when it gets there:

						mv test.c CP367/test_2.c
  1. When using ls -la , the files are listed with a number of different items on the line. Identify what the following means:

    • the first character on the line.
    • in general terms, the next nine characters on the line.
    • the numbers in the sixth column (after the student/users column).
    • what do the . and .. entries mean?

  2. Determine what the following commands do, and their basic syntax:

    • cd
    • rm
    • mkdir
    • rmdir
    • head
    • tail