The most basic commands of unix

This is really the most basic set of cammands you will need to do basic stuff on your unix workstations. If you need more extensive help, the following web-site has excellent documentation on all topics! Unix Help for Users

Starting Up

Before you start up, please download this file, and store it under the name .cshrc_user in your unix home directory. Note that the name must be exactly as above (starts with a dot).

STEP 1. Copy-and-paste the file into a notepad file called .cshrc_user on your PC
STEP 2. ftp the file over to your Unix account.

Notation

I use the following notation: Each UNIX command is shown in a line starting with the basic unix prompt, the "%" sign. You do not have to type this in unix. The command is typed in red color. The output is in green color, and my notes are in black.

Directories (similar to Folders of windows)

To show what files are in my directory:

% ls

ajfile1.doc	ajfile2.doc	ajfile3.text
As shown, there are three files in my directory.
How do I know which directory am I currently in ?

% pwd

/staff/ie/joneja

In your home directory (the directory in which you are when you first log in, there are also some hidden files. You can see the names of these files by using an option with the ls command. All hidden files have names starting with a dot, example: .cshrc_user or .login_user

% ls -a

.login	.login_user	.cshrc	.cshrc_user
ajfile1.doc ajfile2.doc ajfile3.text
Of the above hidden files shown, the files called .login_user and .cshrc_user are similar to the AUTOEXEC.BAT and SETUP.INI files in DOS. You can edit the .cshrc_user file, to customize your unix environment. For example, you could get unix to automatically display your current working directory instead of the usual promplt ( % ). Read the section under Index of 'S', on topic Setting Prompt, in the Unix documentation to see how this is done.

Creating a new directory

% mkdir public_html

This creates a directory called public_html. You can see this new directory by using the usual command to list contents of a directory, ls:

% ls

ajfile1.doc	ajfile2.doc	ajfile3.text	public_html
Changing directories: You can move between directories (folders) in exactly the same way as you do in DOS. The command is called "cd".

% cd public_html

% pwd

/staff/ie/joneja/public_html

% ls

You will see that this time, there is no output, since there are no files as yet in the directory called public_html.


Working with files

Creating new files:

You create new files using a text-editor. A popular editor at UST is called pico. It works nearly the same as the EDIT command in DOS.

% pico index.html

This command will start the editor and allow you to create a file called index.html. If you already have a file of that name in the current directory, then it will open this file for modifications.

Copying a file: the "cp" command can make a copies of a file:
Usage: cp ORIGINAL-FILE-NAME NAME-OF_COPY

% cp index.html index.backup

% ls

index.html	index.backup

Deleting a file: delete a file by using the "rm" command, followed by one or more file-names. You may use *, or *.*, etc. in the file-names.

% rm index.backup

% ls

index.html

Renaming a file (changing the name of a file): this is done by using the "mv" command, as follows:

% mv index.html NewNameFile

% ls

NewNameFile

chmod command: IMPORTANT for web-page maintenance

One final command that is useful for web-page maintenance requires some explaining. In unix, file access attributes are described by the following specifiers: Each file can be accessed by YOU, a GROUP of users specified by you, or by OTHERS (that is, all users of the computer). Further, each of these three sets of users (you, group, or others) are allowed to either READ the file, or WRITE to (modify) the file, or, if the file is an executable program, EXECUTE the file. Therefore there are NINE attributes for each file:
READ, WRITE, EXECUTE for each type of users: OWNER (You), GROUP, OTHERS.

These attributes of a file are shown by the long-form output of the "ls" command:

% ls -l

1   -rw-r--r--    1    joneja          4     Feb 4 16:13      index.html

The output of "ls -l" has a lot of information, as follows: Size of file in blocks (each block can hold up to 1024 Bytes), Attributes list, number of links to the file (ignore this for now), owner of the file, number of Characters/Bytes in the file, the last time it was modified, and the file name.

Let's look at the attributes of the file; I will separate them into four groups:

-, rw-, r--, r--

The first character indicates the file type ( - means it's a data file, d means it is a directory).
The next three characters indicate the attributes for the owner: rw- means the owner (in this case, joneja), can read, write, but NOT EXECUTE the file.
The next three characters, r-- mean that any group which can also use this file, as specified by the owner, can read this file, but cannot WRITE, and cannot EXECUTE this file.
Similarly, the last three characters, r--, indicate that OTHER users can only read the file, but not execute or write to it.

In order for your web pages to be accessible to other people, you must change the mode (attributes) of the files in the following way:

(1) The directories public_html and all its sub-directories must be EXECUTE open for all users. Do this by typing:
% cd ~

% chmod a+x public_html

(2) All HTML and IMAGE files should be read open to ALL (owner, group, others).
% cd public_html

% chmod a+r public_html

(3) All CGI files must be executable for all (owner, group, others).
% mkdir cgi-bin

% cd cgi-bin

Now edit all your CGI files (you will learn how to write CGI-scripts soon!)

% chmod a+x *

The "*" above means ALL files in the directory.


Using Perl and Sybase

You will use two unix programs extensively in this course. The first is perl. In fact, perl is a program that interprets and executes 'commands' that you write in the perl language. Your commands are stored in a file that you call your perl script. If you write your perl script in a file called MyFile.perl than you can execute this script by typing

% /usr/local/bin/perl MyFile.perl

However, it is convenient to tell Unix that the 'perl' command resides in the directory called /usr/local/bin/, by doing the following:

% cd

Now edit the file called: ".cshrc_user"

In this file, add this line at the end:

setenv PATH /usr/local/bin/:$PATH

After this line, add another line as follows:
setenv SYBASE /usr/local/sybase

since you will be using commands for sybase, it is better to also tell unix where the sybase commands are located, by adding the following line at the very end:

setenv PATH /usr/local/sybase/bin:$PATH

Save the .cshrc_user file, and exit the editor. Now run through the following unix command:

% user-setup

The command gives you many choices. Select choice 4, for database, and then select choice 2, for sybase. After you are done, save, apply, and quit.
However, you will only be able to run sybase later in the semester, after accounts have been created.


This is a very short UNIX introduction. You will need other commands -- the best way to learn them is (a) ASK you friends (b) ASK your TA, Instructor, (c) Read the manuals.

In Particular, the UNIX Users Information page is a great introduction, as well as a good user's manual !