Introduction to Unix




Intro to Linux/UNIX Course



Check the LTS Workshops page for information on when the next class is offered. The Intro to UNIX presentation is online.

What is Unix?



Unix is a multiuser, command line-based operating system. With Unix, you can remotely log into a computer and work with it as if you were physically seated at the machine. Your UNet account is Unix-based, which allows you to check your e-mail using Pine, and use the command line to manipulate files and run commands and scripts.

Getting Started



RedHat network activation key information is available at: https://unet.brandeis.edu/accounts/rhn.php.

Logging In



Before you can check your e-mail, or use any of your account's other functions, you must make yourself known to the Unix computer you are trying to connect to. Using SSH you can connect to the Unix computer. Once connected, you will be asked to authenticate yourself. In order to do this, you will need a login name and password. A successful login will look like this:

joeschmo@diane's password:
Last login: Wed Aug  7 12:38:17 2002 from dhcp-129-64-160-10.brandeis.edu
Last reboot at 07:24:33 PM on Thursday, June 6, 2002 EDT
Red Hat Linux release 6.2 (Zoot)
Kernel 2.2.19 on an i686
$



In this example, the first line is a prompt for the user's password. The line directly following the password shows the last time this user was logged in, and where he/she was logged in from. The following line displays the last time the host being logged into was restarted. The next two lines that are displayed are the type of system to which you are logging in, in this case a Red Hat Linux system, and the type of processor, in this case an i686 (an Intel Pentium II). Any messages of the day or important information are then displayed, and finally, the user gains access to the system. In this case, the user is given a Unix prompt. All users will get a menu system rather than a Unix prompt when they login, but everyone will have access to the Unix prompt through the menu system. More advanced users can turn the menu system off altogether. In some cases you will also be prompted for a terminal type; in almost all cases the terminal type should be set to VT100.

Using the Menu system



Unlike previous years, users now have a choice between using a menu system or using a command prompt. Users who are unfamiliar with the Unix operating system, will want to use the menu system.

The options in the menu are:

Mail - Send and receive electronic mail with Pine

WWW - Browse the World Wide Web with Lynx

SSH - Secure Shell login to a remote computer

Telnet - Insecure telnet to a remote computer

Home Dir - Browse or edit files in your home directory with Pilot

Brandeis - Search the Brandeis directory

Ytalk - Talk over the Internet with ytalk

Finger - Finger a User

Password - Change your UNet password

Exit - Exit menu system to tcsh command shell

Help - A few pointers to available help

Q - Log Out

Basic File Manipulation From the Command Prompt:



How do I list my files?



Type ls at the $ prompt. ls will give a list of the files in the default manner, which is a multi-column output.

As with almost all Unix commands, ls can be used with various options to change the output.

ls -a lists all (hence -a) files in a specified directory

$ ls -a
.              .bash_history  .bash_profile  .login       WWW
..             .bash_logout   .bashrc        .plan        private
$



Any file that begins with a "." is considered a hidden or system file, and is not normally displayed. In this example there are four relevant files, three of which would not be listed without the -a option. The .login file is a system file that is loaded every time you login. It may contain things such as aliases (see below), or a stylized prompt (also see below). When a person fingers your account the contents of the .plan file are displayed. WWW is not a file (although from this output it is impossible to tell that without knowing), it is a directory where all of your web page files are stored. Finally, mail is the directory where information about E-mail is stored.

ls -F (note the capital F) will tell you if a file is a directory, or not. Different options can also be combined, such as ls -aF:

$ ls -aF
./             .bash_history  .bash_profile  .login      WWW/
../            .bash_logout   .bashrc        .plan       private/
$



Notice the slash after WWW and private, this indicates that these two are not files, but are directories, both of which contain separate files. If a file has an * after a name it means that the file is executable.

ls -l lists the files in a long format, showing all file information, including files size, and file permissions. If we combine -aF with -l this is what we get:

$ ls -laF
drwx--x--x   13 joeschmo joeschmo   2048 Jun 22 12:24 ./
drwxr-xr-x   22 root     root        512 Mar 28 13:50 ../
-rw-------   1  joeschmo joeschmo    124 Jul 21 15:33 .bashrc
rwxr-xr-x    1  joeschmo joeschmo     93 Apr  2 23:38 .plan*
drwxr-xr-x   5  joeschmo joeschmo    512 Jun 17 16:25 WWW/
drwx------   2  joeschmo joeschmo    512 Jun 22 12:24 mail/
$



Notice the different columns listed. They each tell a different piece of information about the files. The first column, for example, is the file permissions (see below for more information on file permissions). The third and fourth columns shows the owner of the file, and the fifth column is the size of the file.

Deleting files



Now that you can view all of your files, you need to be able to control them. The command to delete files is rm filename (which stands for remove) where filename is the name of the file you want to delete.

$ rm .plan
$



The above command would delete a file named .plan. It is important to be very careful when deleting files. In Unix, there is no undelete command, once a file has been deleted it is gone forever.

Copying and Moving files



The commands to copy and move files are very similar, they are cp and mv, respectively. mv moves a file to a new destination, deleting the file from the original location. The cp command leaves the file in its original location while making a copy of the file in a new destination. The syntax for both commands are the same: mv filename destination.

$ mv foo bar
$



This command moved a file called foo to a file called bar. The same command could be used for moving directories as well. For example, if, in the above example, foo had been a directory the entire directory and all of it's subdirectories would have been moved to a new directory call bar.

Creating and Deleting Directories



A directory in Unix is analogous to a folder on a Mac or Windows 95 machine, it is a place where files and other folders can be stored. For example, all of the files for your web page are kept in a folder called WWW, which is inside your home directory. A directory such as .www, which is nested inside another directory, is called a sub directory. Your home directory is where all of your files are stored by default.

The command to create a directory is: mkdir and the command to delete one is rmdir (make directory and remove directory, respectively)

$ mkdir WWE
$ rmdir WWE
$ mkdir WWW
$



In the short sequence listed above, a user tried to create a web directory, but mistyped it, (it should have been WWW instead of WWE). The user then removed the errant directory, and created another one, this time with the correct name.

File permissions



What are permissions?



Now that you can create files and directories on the Unix system, it is important to know how to keep these files safe. Each file and directory has 3 sets of 3 permission settings (for a total of 9 settings) attributed to it.

Each set if for a particular set of users on the Unix system. These are: user, groups, and other. User denotes the owner of this file, if the file is in your home directory, then most likely the owner is you. Groups would be everyone in a particular group, for example, if you are an undergraduate, you would be in the student group. And other is everyone else, for example people accessing your files from the web, rather than being logged on directly to the Unix system.

For each of these types of users, there are three different permission settings. They are read, write, and execute. Read means that users can read (i.e. copy, another computer, send in an e-mail) any file that has read permissions set. Write means, obviously, that users can write to that file, they can edit it, make changes, etc. The last attribute, execute, means that users can execute that file. For example, if a user wrote a program, and wanted to run that program, the file would need to be executable.

How do I tell what the permissions of a file are?



To check the file permissions, use the ls -l command. For example, if you wanted to check the permissions on your index.html file, a file that is used for your web page, it would look like this:

$ ls -l index.html
-rw-r--r--   1 joeschmo joeschmo   394 Jun 14 01:54 index.html
$



This first column is the one that we want to look at. Excluding the first dash, there are 9 different settings. The each are rwx (read, write, execute), three times over (once for each type of user). So, for this file, the owner of the file can read, write, and execute it, while everyone in the student group, as well as any "other" users (in this case, most likely a user view your web page) can read and execute it.

Any files that get put into your WWW directory will automatically have the correct permission settings. If, for any reason, you need to change those settings, please follow the instructions below.

How do I change the permission settings of a file?



The command to change the permission settings of a file in Unix is chmod. The syntax is:

chmod [ugoa]{+|-}[rwx] file

where [ugoa] is one of the following: user, group, other, and all. + and - are the operators that you want to use, either to set the permissions (using +), or to remove the permissions (with -). [rwx] are, as stated before, read, write, and execute. Finally, file is the file that you would like to change the permissions for. For example, if you wanted to change the permissions on the index.html file, so that everyone can view it on the web, but only you could make changes to it, you would want user to be read and write, but groups and others should only be able to read. It would look like this:

$ ls -l index.html
-rw-------    1 joeschmo joeschmo   394 Jun 14 01:54 index.html
$ chmod go+r index.html
$ ls -l index.html
-rw-r--r--    1 joeschmo joeschmo   394 Jun 14 01:54 index.html
$



In this example, the user first checks to see what the permissions on the index.html file are, and see that they are set incorrectly. The owner of the file can read, write and execute the file, but the groups and other fields are all blank. The user then issues the chmod command with the arguments go+r which gives read permissions to users in the same group as the user and to all other users as well.

E-mail



To send e-mail from your Unix account you should use the pine program. To access it, select pine from the menu or type pine from the % prompt. For more information on Pine, please see the Pine documentation.

Forwarding Email





If you would like to have your e-mail forwarded to another address please use Netscape and go to https://unet.brandeis.edu/ and follow the online instructions.





This page was last modified on: Mar 23, 2007