A Brief Tutorial for Unix (and Linux)

File Structure

Like Windows and MacOS, unix and linux files are hierarchically organized. Inside of one's home directory (i.e. folder) reside files and subdirectories. Furthermore, each subdirectory may hold more files and another level of subdirectories, and so on.

Files and directories can be specified in absolute and relative terms. Here is an example of an absolute reference to an example home directory:

/export/home/stu/smith

In this case, "smith" would be the user's login directory. Each slash represents one level down in the directory hierarchy. Here, "export" is a subdirectory in the "/" directory. "home" is a subdirectory in the "export" directory. "stu" is in the "home" directory, and finally "smith" is in the "stu" directory. All absolute references start with a slash.

If there were a file named "data" in Smith's directory, it could be referenced in absolute terms in the following way:

/export/home/stu/smith/data

If there were a subdirectory named "Mail" in Smith's directory and a file called "letter" inside of that, it could be referenced as

/export/home/stu/smith/Mail/letter

By the way, file and directory names are case-sensitive in unix. So, the filenames "mail" and "Mail" would refer to different files.

Relative references to directories and files are always in terms of the current working directory. The unix command "pwd" writes out what the current working directory is. When a user first logs in, the computer sets the working directory to be the user's home directory. With a relative referencing, a user can directly specify a file in the current directory. For example, if the current working directory is the home directory and "data" is the name of a file in that directory, the reference "data" would refer to that file. Similarly "Mail/letter" would refer to the file "letter" inside the "Mail" directory that is inside the home directory.

Here are some shorthand notations for specifying files and directories in absolute and relative terms;

Common commands

Typically commands are followed by directory or file references that the command operates on. Sometimes commands have options that are specified by a hyphen then a letter (e.g. see the ls command below). More information about a command can be found by typing man followed by the name of the command.

Editing files with nano

Nano is a simple text editor that is common on Unix systems. To edit a file using nano, type the command nano filename. The nano editor will list basic commands at the bottom of the screen. The command CONTROL-G will display some additional documentation on how to use the editor. To exit (and optionally save changes), use the command CONTROL-X.

Running the script command

With the script command, it is possible to automatically record a session of your actions and their output. To start a script session, type the command script filename. After you type this command everything that appears in your terminal will be written to your specified file. To end the session, type CONTROL-D (ie. hold down the control key and then hit the letter D).

File Permissions

Unix allows users to control who has access to their files and directories. For example, they may prevent others from modifying any of their files, give others the right to only read some of their files, and deny all access to another set of files.

Each file (and directory) has a set of permissions that control who has access to it. To find out what the permissions are for a particular file, type ls -l in the directory where the file is located. This command lists all of the files in the directory and their access permissions. The following is an example listing from this command:

whoville% ls -l
total 9558
drwxr-xr-x   5 miller   faculty     1024 Aug 12 09:46 Call
drwxr-xr-x   9 miller   faculty      512 Oct 23 13:37 efh
-rw-r-----   1 miller   faculty  4882432 Jun 24  1998 Lex.tar
drwx--x--x  13 miller   faculty      512 Oct 23 13:31 SCA

This listing shows one file and three subdirectories inside the current working directory. The first column for each entry (file or subdirectory) shows the entry's permissions. The first character in this column indicates whether the entry is a file or a directory. The next three characters show what the entry's user (typically the person to whom the account belongs) may do with the file. In this case, the user may read or write (ie. modify) the file Lex.tar. The next three characters show what permissions people in the user's group may modify. In this case, people who are in the faculty group have read access to the file. Finally, the last three characters show what access other people have to the file. In this case, people who do not belong to the faculty group have no access (read or write) to the file.

The x indicates that the file or directory may be executed. In order to access a directory, it must be executable. To check if your home director (folder) is public executable, type in the following commands:

ls -ld ~

The command chmod allows a user to change the permissions to a file directory. Here are some examples and what they do to the above file:

Here is a tutorial on permissions and the chmod command.