Unix Cheat Sheet

Here are some of the most used commands in Unix and their action :


To login to your account :

login: Alex

Password:

This logs in the person who has been given the username Alex on this system. UNIX is case sensitive. If your username is "Alex", do not enter "alex." Your password is never displayed on the screen. If it were, other users might see it!


Files

In Unix every thing is a file, so to be able to understand Unix you should have an idea how to work with files.

To see what files you have in your directory you type "ls", which stands for list, but this won't show you all the files in the directory, to do so you should type "ls -a" where the "a" stands for all. To get a full list with a summary about each file and directory you type "ls -al", and typing "ls -alFt" will list all the files with last time of access for the file and a summary about each file. For example you may see something like :

drwxr--r-- 5 abdoawas abdoawas 1024 Jan 7 13:20 Desktop/
drwxr-xr-x 2 abdoawas abdoawas 1024 Jan 28 10:53 fortran/
drwxrwxr-x 2 abdoawas abdoawas 1024 Feb 3 17:41 html/
drwx------ 2 abdoawas abdoawas 1024 Jan 27 20:28 mail/
drwx------ 2 abdoawas abdoawas 1024 Jan 16 12:08 nsmail/


Her The first item -rwxr--r-- represents the access permissions on this file. The following items represent the number of links to it; the username of the person owning it; its size and the time and date it was last changed, and finally, its name. But how to understand the access permissions, well its easy :

There are three types of permissions:

r read the file or directory

w write to the file or directory

x execute the file or search the directory

Each of these permissions can be set for any one of three types of user:

u the user who owns the file (usually you)

g members of the group to which the owner belongs

o all other users

The access permissions for all three types of user can be given as a string of nine characters:

user - group - others

r w x-r w x-r w x


Changing access permissions :

To change the access permissions for a file or directory use the command

chmod mode filename

chmod mode directory_name

Setting access permissions numerically

There is a shorthand way of setting permissions by using octal numbers. Read permission is given the value 4, write permission the value 2 and execute permission 1.

r w x

4 2 1

These values are added together for any one user category:

1 = execute only

2 = write only

3 = write and execute (1+2)

4 = read only

5 = read and execute (4+1)

6 = read and write (4+2)

7 = read and write and execute (4+2+1)

So access permissions can be expressed as three digits. For example:

user group others

chmod 640 file1 rw- r-- ---

chmod 754 file1 rwx r-x r--

chmod 664 file1 rw- rw- r--


copying files

copying files from the same directory

cp [file name] destination

for example

cp lineq.f lineq2

copies the file lineq.f to the file lineq2

Copying files from another directory

To copy a file from another directory to your current directory give the pathname to the source file followed by the name of the destination file

cp path_to_source file destination


Creating Files

Creating a file with the Vi text editor

To open a file using the Vi text editor just type

vi [file name]

For example

vi test.txt

creats the file test.txt which is a text file. This will put you in the command mode in the Vi text editor to switch to the Insert mode press "i", now you can write whatever you like, then when you finish press Esc this will take to the command mode again to write the file and quit you should type wq

Deleting Files

To remove a file use the command:

rm filename

To remove a directory use the command:

rmdir directory_name


Finding a file

To locate a file in the file system , use the find command.

find pathname -name filename -print

The pathname defines the directory to start from. Each subdirectory of this directory will be searched.

The -print option must be used to display results.


Moving files

to move a file:

mv [file name] destination file


Printing files:

To print a file use the command:

lpr filename

The job is placed in the print queue and you can carry on working.


Compiling Fortran files

To compile a Fortran file in unix you should first know what version of Fortran available on your workstation. Gauss supports both, Fortran 77 & Fortran 90.

For example

g77 file.f -o file.out

here you compile the file file.f and store the result in the file file.out, now to execute the file you type
./file.out


Back