UNIX Concepts

Directory
The UNIX concept of a directory is just like the Mac concept of a folder. Directories hold files and other directories. The UNIX system contains lots of directories in a nested structure.
Subdirectory
A subdirectory is simply a directory that is inside another directory. Since UNIX only has one top level directory, called the root directory, every other directory can technically be called a subdirectory.
Root directory
The top of the directory hierarchy on any UNIX system. It is represented by the directory named with just a slash, as in /.
Current or Present working directory
The current or present working directory is the default directory for UNIX commands. For example, using ls by itself lists files in the current directory. If you want to access files other than in the current directory, you have to use either a relative pathname or a full (absolute) pathname.

When you log in, your current directory is your home directory.

Home directory
Your home directory is the directory allotted for all your stuff. It, and the files and subdirectories under it, are all yours.

If you are in a CS course (and are not a CS major), your home directory will be:

/home/course/csXXX/username

This just means that your home directory is under the csXXX directory, which is under the course directory, which is under the home directory, which is under the root directory, i.e., /. This, of course, is an example of a full pathname.

Path or Pathname
A path or pathname is simply the set of directories that have to be traversed to get to a file. In other words, it is a way of giving an address for the location of a file, like a mailing address for a letter.

An example path would be:

homeworks/hw1/prog1.cpp

which refers to a file called prog1.cpp in the directory hw1, under the directory homework under whatever your current directory is. Note the use of the slash (/) to separate the pieces.

Typically you'd use a path to tell a command what file to operate on. For example,

ls -l homeworks/hw1/prog1.cpp

uses ls to list information about the file prog1.cpp. Since, in this case, prog1.cpp is not in your current directory. you must give a path with the file name.

Full or Absolute pathname
A full pathname is just a path that starts at the root directory, i.e., begins with the slash (/) character.

Any example full path is:

/usr/bin/man

which is the location of the man command.

Relative pathname
A relative pathname is just a path that starts from your current directory, and thus, doesn't start with a slash (/) character.

Any example relative path is:

homeworks/test1

which refers to a file in the subdirectory homeworks under your current directory.

Command Argument
Command arguments are those things that are typed at the prompt after the command name. Arguments are usually separated from the command and from one another by space. An example would be:

ls -l homework

where the command name is ls and the arguments are "-l" (a special kind of argument called a flag) and "homework".

Command Flag or Option or Switch
Command flags are typed at the prompt as part of a command. An example would be:

ls -l

in which case the flag -l (minus ell, not one) gives a longer set of information. Flags alter the default behavior of commands. For example, the command ls, by default, just lists the names of files. With the -l flag, it gives you more information about each file (or directory).

Flags normally start with a minus sign (-) and consist of a single letter, like l (i.e., ell) or a whole word, as in -debug. For commands that take only single letter flags, more than one flags can often, but not always, be combined. For example, -l and -F could be typed as -l<SPACE>-F or -lF. In some cases, flags will start with a plus sign (+) instead. It is more typically for flags with pluses to be part of a pair of flags, e.g., -a to turn some feature on and +a to turn it off.

Because some flags turn features on/off, flags are sometimes called switches. In addition, they may be called options.

Text file/Binary file
A text file is just like any other file, but it mainly contains letter, digits and punctuation characters. So, a textual e-mail message or the source code for a program is often stored in a text file. Since the coding we use for letters, etc. (in most computers) is the ASCII (pronounced ask-key) code, text files are also sometimes called ASCII files.

Types of files that are not text files are executables and word processor documents and are called binary files. When you try to view binary files with text file commands, they look like garbage. Again, a text file only differs from a binary file in that information is stored in it using the typical symbols that you'd see on a typewriter.

Source Code
A source code file is a file that contains program code in C++ (or some other language). For C++, these files usually have names ending in .cpp (and sometimes in .h). These files cannot be run on the computer. In order to get an executable, which can be run, you must compile and link the source code.
Executable
An executable is a file that contains a program that is ready to run. When using ls to view files, these executables often have an asterisk (*) after their names (though the * is not part of the file's name).

To run an executable, you just type its name.

Compiling and Linking
Compiling and linking means to turn source code into an executable that can be run on the computer.

Compiling and linking are actually separate procedures, though often you'll use one program to both compile and link. Technically, compiling puts all the source code into an intermediate form and linking links all the intermediate pieces and special libraries into a single executable.

Often we'll use the term compiling for both compiling and linking.

We'll compile and link our C++ programs by using the g++ compiler or by using the make utility.

Debugger
A debugger is a program that allows you to examine what an executable is doing while it is running. It is useful in finding errors in programs that compile fine, but that don't do what you want them to.

Our debugger is gdb.

Running a program in the Background
Running a program in the background just means that while you are running the program you can do other stuff on the machine. This is exactly what we do when we use the ampersand (&) at the end of a UNIX command, so that we get the prompt back right away.

If a program is not running in the background, we say it is in the foreground.

Redirecting input into a program
Many programs require you to give them some input. Usually the program expects input to be typed at the keyboard. Sometimes, however, you want to put that input in a file instead (for testing, etc.).

UNIX allows you to use the less than (<) character to make the program take input from a file instead of the keyboard.

Redirecting output from a program
You can capture the output of a program and send it into a file.

UNIX allows you to use the greater than (>) character to send a program's output to a file instead of to the screen.

Piping output from one program into another
You can capture the output of a program and send it directly as the input to another program.

UNIX allows you to use the pipe symbol (|) to send a program's output into another program.

Command History
When you type UNIX commands on our system, a record (or history) of these commands is kept for your login session.

Using the up and down arrow keys, you can scroll to a previous command, edit it (or leave it as is) and then press <RETURN> to perform it again.


BU CAS CS111/112/113 - UNIX Concepts
Copyright © 1993-2000 by Robert I. Pitts <rip at bu dot edu>. All Rights Reserved.