Introduction to the Operating System UNIX (2)

The previous web page should be sufficient for most needs at this stage.

Here more information about UNIX are presented, which you may find useful later.

You need not master everything in one go. Remember R. Courant's teaching of "not trying to master everything in one go, but time and again return to the difficulties".

Get some idea of them, and return to them when you need them.

Organization of Directories in Unix

In Microsoft's Window, you will find, under C:, directories like "Windows", "Multimedia Files", "Program Files" etc. In UNIX, the directories to store system files are named differently.

The following diagram shows the most common system directories

IT IS STRONGLY ADVISED THAT YOU STORE NOTHING IN THE SYSTEM DIRECTORIES, BUT STORE EVERYTHING UNDER /HOME/ DIRCTORY.

The reason is for backup purposes. If everything that changes are stored under "/home/", then we have only to "backup" this directory. Should the system fails one day, the system may be re-installed through the CDROM, and this directory "/home/" alone. (It is assumed that we do not start from a "bare" system and add "packages" frequently.)

You may "change directory, cd ... " to the directories listed above, and see what files are there, "dir * | more"


Permissions, etc.

UNIX is designed for multi-users. There is a "super-user" (whose user ID is "root") in UNIX who can access any files in the system. But for ordinary user, he may only access the files under his own directory, e.g. /home/robert/, or system directories where permission has been granted.

There are 3 kinds of permissions for a file,

                read                       user may read the file
                write                      user may write to the file
                execute                    user may execute the file.

Also, "read, write, execute" permissions may pertain to "owner of file", "group" where owner is a member, or "others", i.e. any other users not the owner, nor the group that includes owner.

Bit 0 is "execute", bit 1 is "write", and bit 2 is "read". "1" means "permission granted", "0" means "refused". The permission of the file in picture is 711 (octal number).

Exercise : If the "owner" has "read, write" permission, and "group" or "others" have "read" permission, what is the permission in octal ?

Ans : It is "110-100-100" or 644 in octal.

chmod u+rwx filename
[change mode]
       r = read
       w = write
       x = execute

       u = user
       g = group
       o = others

       +   permission granted
       -   permission taken away

Exercise : If we give "psin.c" read permissions to "group" and "others", what is the command ?

Ans : chmod go+r psin.c

Exercise : If we take away all permissions from "group", "other" for the file "psin.c", what is the command ?

Ans : chmod go-rwx psin.c

Exercise : If we do not want "psin.c" to be modified by us accidentally, what is the command?

Ans : chmod u-w psin.c

Exercise : What does the command "chmod 700 psin.c" mean?

Ans : User has all permissions, but "group, others" have none.

Exercise : What does the command "chmod 644 psin.c" mean?

Ans : User has "read, write" permissions, but "group, others" have "read" only.

Exercise : What does the command "chmod 711 psin.c" mean?

Ans : User has all permissions, but "group, others" have "execute" only.

Exercise : What does the command "chmod 711 *c" mean?

Ans : For all files in the current directory whose names end with "c", user has all permissions, but "group, others" have "execute" only.

(Note : "permissions" may be used for directories too. "Read, write" has the usual menaing, but "execute" means "read" only.)


When you issue the command vdir filename, you will notice that

drwxr--r--
The first letter has meanings : (d = directory, b = block device driver, e.g. disk driver, c = character device driver, e.g. terminal, - = ordinary file). The rest are permissions for owner, group, others.


How to make a library

Exercise : Suppose your directory is /home/tom/, how are you to make a directory name "lib" under it. In this directory "/home/tom/lib/" will be stored all libraries we will use.

Ans : If we are currently in /home/tom/, then

mkdir lib
otherwise
mkdir /home/tom/lib


Now suppose we have written several subroutines : "quad.c" for solving quadratic equations, "root.c" for finding root of a non-linear equation, and "equation.c" for solving simultaneous linear equations. We wish to put all these in a library file, say "libtest.a" under /home/tom/lib/.

The commands to do them is

gcc -Wall -c quad.c
gcc -Wall -c root.c
gcc -Wall -c equation.c
ar -rsv /home/tom/lib/libtest.a quad.o root.o equation.o

OR

ar -rsv lib/libtest.a quad.o root.o equation.o

if we are currently in /home/tom/

The "ar" command

General format of the "ar" command is
ar [-options] libraryname objectfile1 objectfile2 ....
Where "options" may be
-r Replace object files with those provided. It is also used to insert object files.
Note that library file name must be in the form "lib .... .a", i.e. it begins with "lib" and have extension ".a". If this "libraryname" does not exist, it will be created.
If an object file already exists in the library, say "objectfile1", it will be replaced with those supplied.
-v Verbose. You should supply this, so that what "ar" does will be printed on the screen.
-d Delete. "objectfile1 objectfile2 objectfile3 .... " will be deleted.
-x Extract. "objectfile1 objectfile2 objectfile3 ...." will be extracted from "libraryname". Notice that they are still in "libraryname". Only copies are extracted from the "libraryname".
-s Index. It commands "ar" to create a "index file". "Index file" are important, when subroutines call one another in a complicated ways.
-t Table of Content. List all the object files in the "libraryname".

Examples

ar -rsv /home/tom/lib/libtest.a quad.o root.o equation.o
("ar" will create the library "/home/tom/lib/libtest.a" first, if it doesn't exist) Replace/insert the binary files "quad.o, root.o, equation.o"
Create the "index table" and shows everything "ar" does, i.e. verbose mode.
ar -t /home/tom/lib/libtest.a | more
List all the object files in the library "/home/tom/lib/libtest.a" (table of content).
ar -rsv /home/tom/lib/libtest.a quad.o
Suppose we have modified the subroutine "quad.c", and have compiled it with "gcc -Wall -c quad.c", and we are to insert this newer version into the library.
"Index table" is to be updated too.
ar -xvs /home/tom/lib/libtest.a root.o equation.o
Extract copies of "root.o equation.o" from the library. They are still in the library, only copies are made.
ar -dvs /home/tom/lib/libtest.a root.o equation.o
The two object files "root.o equation.o" will be deleted from the library.

How to use the libary

Now that we have created a library. Suppose the program "psin.c" needs the subroutine "quad.o", then we will have to use the command

gcc -Wall -o sintable psin.c -L/home/tom/lib/ -lm -ltest

"-o sintable" means the executable binary file is "sintable", and not "a.out".

"-Ldirname" = "-L/home/tom/lib/" means the library in stored in the directory "/home/tom/lib/". We must tell "gcc" where we store the library file. "gcc" by default will search "/usr/lib/".

"-lm -ltest" means we use two libraries "libm.a" and "libtest.a". The former is a system library and is stored in "/usr/lib/", the latter is our library stored in "/home/tom/lib/"

Exercise : Suppose "psin.c" needs "quad.c" and "root.c", and we do not want to use "library", what is the command ?

Ans :

gcc -Wall -o sintable psin.c quad.c root.c -lm

Exercise : Suppose the source file is "prog1.c", and we want the executable binary file to have name "pro". "prog1.c" uses 2 libraries "libp1.a" under /home/john/lib and the usual Maths library, "libm.a". What is the command ?

Ans :

gcc -Wall -o pro prog1.c -L/home/john/lib/ -lm -lp1

Header Files stored not in "/usr/include"

(You may not understand this section now, but when you have learned some C, you will.)

The standard header files are usually stored in directory "/usr/include/". For users, it is inadvisable to store header files there.

We may make a directory in our directory, e.g. "/home/tom/include/", and put all our non-standard header files there. Now to inform gcc that we store header files there, we will have to use, e.g.

gcc -Wall psin.c -I/home/tom/include/ -L/home/tom/lib/ -lm -lp1
Here the option "-I/home/tom/include/" informs the gcc compiler to search "/home/tom/include/" for header files.

gcc, by default, will search "/usr/include/".

C as a programming language is a "minimal language". You will find the core part of C very small, i.e. without some supplied "standard libraries", a user will practically have to build up a computer system from scratch! like what the Assembler programmers did in the past with a new computer! (Nowadays, ANSI Standard C comes with a set of libraries).

With "ar", user can create libraries of their own. Hence C would be extremely laborious to use at first, but gradually, when one's library has grown, he will find it easier and easier to use (usually it takes two to three years to build up all your library subroutines).

In UNIX, every C program can also be a command (you will find out later), i.e. once you have written a C program and have compiled it, you may use it as a "command", like all the other commands in Unix. Hence user can add more and more commands of their own. It is also the reason why you will find so many commands in UNIX!

You will find that such design philosophy is ideal in building up computer systems.


How to learn more about UNIX online

"man" (meaning "manual") command is the main command to use, e.g

man ar
will tell us how to use "ar" command. The cursor movement keys (up, down) are used to scroll up and down. To quit, type "q". (Ctrl + c to quit will not work here).

"apropos keyword" will tell us all commands related to "keyword", e.g

apropos compiler
will list all commands relating to "compiler".

"info" (meaning "information") is another command to use,

info

You just type "info" and press "Enter".

"info" will display a list of topics available. You have to use the following commands to navigate,

spacebarPressing "spacebar" will scroll down one page.
<-This is the key at the top-right corner, not the cursor movement key. It will scroll up one page. These may be discouraging for us who are accustomed to Microsoft's mouse and scrollbars, and we have to get used to it gradually.
m[menu] You may select the topics you want. Type "m", and you type in the "topic name" at the bottom row.
"Tab" key is used for automatic completion, e.g. if the topic is "make", and if there is only one manual item beginning with "ma", then you type "ma" and press "Tab", then it will be completed as "make". Then you press "Enter".
"ctrl + c" means the usual "stop the program", and may be useful when "info" get mixed up.
p[previous] "p" will bring you to the previous "node, or page".
"info" is a crude form of information system before the invention of WWW, Internet.
u[Up]. The "info" system is organized hierarchically. "u" means moving one level up the hierarchy.
n[Next]. Display the next page.
b[Beginning]. Move back to the beginning of the document.
When we have scrolled down many pages with "spacebar", either we may use "<-" to scroll up page by page, or simply "b", to to go the beginning.
q[Quit]. Leave the "info" command.

Some "LINUX" distributor supply "info" in the form of HTML files (e.g. "Unifix" of Germany) and is more convenient. The command "documentation" will bring up this HTML file. But for most "LINUX", this is not available.


Compressing, decompressing files

gzip filename
"zip" means compression, and software from Free Software Foundation usually begins with "g".

e.g.
gzip psin.c root.c quad.c equation.c
will produce files "psin.c.gz, root.c.gz, equation.c.gz", i.e. with ".gz" appended to the filename. You may use "vdir filename to view the file size.
gzip *c
will compress all files in current directory whose names end with "c".
gzip prog{1,2,3}.c
will compress files "prog1.c, prog2.c, prog3.c" into "prog1.c.gz, prog2.c.gz, prog3.c.gz".

gunzip filename
e.g.
gunzip prog1.c.gz prog2.c.gz
will decompress "prog1.c.gz, prog2.c.gz" into "prog1.c, prog2.c". You may use "vdir ..." to view them.

zcat filename.gz
This is another form of "cat" command for compressed files.
"cat filename" will display content of file on the screen.
"zcat filename.gz" will display content of a compressed file on the screen, without de-compressing it. It is useful when we wish to see the content of a compressed file, but do not wish to change it or decompress it.

Some common "ctrl + .. " keys in UNIX

ctrl + c
This is the first command to learn, it will stop the running program.
ctrl + u
This erases all the commands we have typed in on the current line.
ctrl + s
[Stop] Sometimes the screen will show too much data, and we press "ctrl + s" to stop scrolling. Printing will be resumed when we press "ctrl + q".
ctrl + q
Resume printing on the screen stopped previously by "ctrl + s".
ctrl + alt + F1
"F1" may be "F2", "F3", "F4", ... the keys at the very top.
This resembles "openning multiple windows in Microsoft's Window". You may log in several times with this command, and do different things under different logins. You switch between different tasks with this command.

Notice that "ctrl + alt + Fn" are three keys pressed together.
Tab
"Tab" key, the leftmost key on the second row of keyboard, means "automatic completion". e.g. you want to change to directory "financereport", and no directory nor filename begins with "fina", then you type
cd fina [Tab]
It will automatically be completed as "cd finacereport", and you press "Enter".
If there are other files or directories beginning with "fina", then you press "tab" TWICE, and the system will list all files, directories whose name begin with "fina" at the bottom row.
The "up" arrow cursor key
If you want to execute a previously typed in command, you do not have to type it in again. You press the "up-arrow cursor key", and the commands you have previously typed will be displayed one by one. You stop when you find the command you want, then press "Enter". (It is similar to Microsoft's DOSKEY in "autoexec.bat")

Backing Up

Backing Up is necessary because accidents may happen.

It is advisable that you do everything under the directory "/home/", e.g. "/home/tom/", "/home/john/", .... Then you have only to backup all files under "/home/".

Should one day the system fails, you re-install the system using the LINUX CDROM, and then restore the files under "/home/".

If you do not do this, but store files randomly in "system directories", e.g. "/usr/include/", "/usr/lib/", ... then your task of backup is complicated.

The command to backup is "tar".

To restore from backup, we also use this "tar" command, only the "options" supplied to this command have to be changed.

General format of the "tar" command is
tar [-options -f] tarfilename file1 file2 .... dir1 dir2 ....
(Note : "tar" means "tape archive". It originated from the days when backup was usually on tape. Now backup are usually made on another hard drive (or floppy or another "partition" on the same drive).

Where "options" may be
-f"-f tarfilename" specifies the backup file name.
-cCreate backup file. Put all "file1 file2 file3 .... dir1 dir2 dir3 ...." into one file "tarfilename".
-x[Extract] Restore back the files "file1 file2 file3 .... dir1 dir2 dir3 ...." and put them under the current directory, creating the directories if necessary.
-t[table of content] List all files in "tarfilename" but without doing anything to the file "tarfilename". Just list the table of content.
-v[verbose] This option should be used with most commands. It means "print out everything the command does".
-z[zip or unzip] If we are creating a backup file, this option will "compress" the backup file. Hence "tarfilename" we use should have ".gz" at the end to remind us of this fact. (The command will compress even if we do not put .gz at the end of filename. But then we do not the file has been compressed.)

e.g.
tar -cvf /tmp/mybackup /home/
gzip /tmp/mybackup
is the same as
tar -cvzf /tmp/mybackup.gz /home/
Here everything under "/home/' will be put into file "/tmp/mybackup.gz" compressed.

If we are retoring from a backup file which has been compressed, then this option will automatically decompress the file. e.g.
tar -xvzf /tmp/mybackup.gz
will restore all files in "mybackup.gz" and put them under the current directory, decompressing the file "mybackup.gz" automatically.

Examples

tar -cvzf /tmp/abc.gz psin.c root.c quad.c equation.c /home/tom/lib/
(Options are : create, verbose, compression, filename)
Create archive file from files "psin.c, root.c, quad.c, equation.c" and ALL files in the directory "/home/tom/lib/". Compress the resulting file, and put it in "/tmp/abc.gz". Later, we may copy this file onto floppy, or another hard drive. Details will be explained later.
tar -tzf /tmp/abc.gz | more
(Options are : table of content, compression, filename)
List all files in this "archived" file "/tmp/abc.gz"
tar -xvzf /tmp/abc.gz
(Options are : extraction, verbose, (de)compression, filename)
Restores all files in "/tmp/abc.gz", decompressing it first, and put all files under the current directory.

Exercise : How are you to put files "rep1.txt, rep2.txt, rep3.txt" and all files under "/home/john/dir1/", into one compressed file "/tmp/reportbak.gz"?

Ans :

tar -cvzf /tmp/reportbak.gz rep{1,2,3}.txt /home/john/dir1/

OR

tar -cvzf /tmp/reportbak.gz rep1.txt rep2.txt rep3.txt /home/john/dir1/ 

Exercise : Suppose you are currently in directory "/tmp/workdir/" and you type the command

tar -xvzf /tmp/reportbak.gz

What will happen?

Ans : You will find "rep1.txt, rep2.txt, rep3.txt" have been restored in "/tmp/workdir/", also there is a new directory "/tmp/workdir/home/john/dir1/" and all files inside there are also restored too.

Exercise : How are you to inspect the files in "/tmp/reportbak.gz" without retoring them?

Ans :

tar -tzf /tmp/reportbak.gz | more

"tar" are also used in packages. e.g. someone has some software which he wishes to offer free to anyone, then he may "tar" all files in the directory where the software is, and then put the compressed "tar" file in the internet. People may download the file from the internet, and use "tar" again to restore the files.

"ar" command is used mainly for creating libraries, but it may also be used to "archive" files. We may insert/replace files into a "archive" file (i.e. "library" file), extract files from it, or see its table of content.


The commands "ps" and "kill"

ps -a
This will lists all "processes" (or "tasks") currently running in the computer. UNIX is a multi-tasking operating system, hence it may have many processes running at the same time. The process identification number will also be printed.
kill -9 [pid]

This will "kill" the process whose "process ID" is specified, e.g.

kill -9 104
will kill process "104".

This "kill" command is often used in the following situation : a running program suddenly "hangs", giving no response. Then we may log in as "root", i.e. "super-user" on another screen (or terminal), with "Ctrl + Alt + F2" (F1 - F6 usually may be used), then "ps -a" to see all processes, then "kill -9 [pid]" to terminate that job.


Reading files on the Floppy or on the CDROM

With Microsoft's Window Operating System, it is a simple matter to view files on floppy or CDROM. But with UNIX, we have to enter commands to do this.

mount -t msdos /dev/fd0 /mnt

(This command is for floppy)
"mount" is the command.

"-t msdos" is an option, it says "type of file system is MSDOS",
(UNIX can read files created by many operating systems, hence we must specify that the floppy has been created with Microsoft's Disk Operating System).

"/dev/fd0" means "device floppy disk 0". If you have other floppies, they will then be "/dev/fd1", "/dev/fd2", ...

"/mnt/" is a directory under "/" (the topmost directory), it is called a "mount" directory, or "mount point".

Now we may access files on the floppy, e.g.
cat /mnt/file1.txt
will display "file1.txt" in the floppy.
mount -t iso9660 /dev/hdb /mnt

(This command is for CDROM)
"-t iso9660" is the file system usually used on CDROM.

"/dev/hdb" is the "slave drive" on the first hard disk controller.

On a PC Motherboard, you will see two 40-pins connectors. They are the connectors for the hard disk controller. One cable may connect two drives, usually called "master drive" and "slave drive". Hence a total of 4 drives may be connected.

Usually, "/dev/hda" is the hard disk we use (or C: drive in Microsoft's Window), "dev/hdb" is the "slave drive" on the first controller. "dev/hdc" is the "master" on the second controller, and "/dev/hdd" is the "slave" on the second controller.

"/mnt/" is the directory to mount devices. If you have a floppy and a CDROM to mount, then you have to make another directory first, e.g.

cd / ; mkdir mnt1; mount -t iso9660 /dev/hdb /mnt1

Notice that we may put more than one commands on one line, so long that they are separated by ";".

"cd /" changes to the "top-most directory", then we make directory "mnt1", and finally mount "/dev/hdb" on "/mnt1".
df
[Disk free] This command is normally used to see how much disk space left, but it may also be used to see all mounted drives.
umount /dev/fd0
umount /dev/hdb
When we no longer want to access files on them, we may "un-mount" them. Usually when you "shutdown -h now" a system, all drives will be unmounted by the system.
mount /dev/hda5 /mnt
(You may omit this)
Very often, the hard drive can store several Giga bytes, and we may partition the drive into several partitions.

Partitions in the "extended partitions" are /dev/hda5, /dev/hda6, ... and we may mount them.

The file system we use on LINUX is usually "extended 2 file system (e2fs)". And we may use this file system on floppy instead of MSDOS. The way is

mke2fs -c /dev/fd0
mount /dev/fd0 /mnt
"mke2fs" means "make an extended 2 file system". It is another UNIX command.
"-c" means "check for bad sectors".
After that we may mount the floppy, and we need not specify a file system, as the default is "e2fs".


Miscellaneous

command1; command2; command3; ....

We may put more than one commands on one line. The commands have to be separated by ";" e.g.

cd /tmp ; ls *c ; cd
Here we first "change directory" to "/tmp", then we list all files whose name end with "c". After that we return to our own home directory. Notice that "cd" without giving the directory-name means "change back to home directory".

Sometimes the job may need long time to finish, and we do not wish to wait at the terminal, then we may run the job in the background.

e.g. If "sintable" takes a long time to run, then we may

sintable &
The "&" at the end means running the job in the background

To see all the jobs in the background, we issue the command

jobs
We may also bring the job back to foreground, e.g.
fg n%
where "n%" is the job number displayed in the "jobs" command.
(e.g. fg 3%)

command1 && command2 && command3 && ....

"&&" means "and".

If "command1" is successfully executed, then "command2" will be executed.
But if "command1" fails, "command2" will NOT be executed. e.g.
gcc -Wall psin.c -lm && a.out
Then if the compilation is successful, "a.out" will be executed.

Command file

We may put all the commands in a file, say, "/home/tom/comfile", and "chmod u+x /home/tom/comfile", i.e. change the mode of that file so that it is "executable". Now just typing "/home/tom/comfile" will cause all the commands in the file to be executed.

How to prevent accidental deletion of files

In WINDOW, if we want to over-write an existing file, the system will warn us "The file exists, do you really want to save?". This is no so in UNIX. Hence if you use "cp file1 file2" but "file2" exists, then "file2" will be over-written without any warning. For "mv file1 file2" command, the situation is the same. To prevent this, we may use "mv -i file1 file2", or "cp -i file1 file2", or "rm -i filenames". The "-i" options means "interactive". System will ask "overwrite (y or n)?" if destination file exists. We should use this option for "cp" (copy), "mv" (move), and "rm" (remove) to prevent accidental destruction of files.

The "alias" and "unalias" command

e.g.
alias rm = "rm -i"
This command will cause "rm" to be replaced by "rm -i", e.g. if we type "rm *c", it will be replaced by "rm -i *c".

If we want to cancel it, we type
unalias rm

The "find" command

Format of "find" command,

find dirname options

Examples :

find /home/tom/ -name "*.c" -print

Find within the directory "/home/tom/" all files whose name end with ".c" and print the names on the screen. (Note : all sub-directories inside /home/tom/ will be searched too).

find . -size +3k -print

Find within current directory (note : "." means current directory, ".." means parent directory) all files whose size are greater than 3k bytes.

find . -size -3k -print

Find within current directory all files whose size are less than 3k bytes.

find . -size 3k -print

Find within current directory all files whose size are roughly 3k bytes.

find / -mtime 3 -print

Find from the topmost directory (and all directories under /) all files whose "modification time" is 3, i.e. the files have been modified in the last 3 days.

find / -atime 4 -print

Find from the topmost directory (and all directories under /) all files whose "access time" is 4, i.e. the files have been accessed in the last 4 days.

find /home/john/ -type d -name "pl*" -print

Find within the directory "/home/john/", all directories (-type d) whose name start with "pl".

find /home/john/ -type f -name "pl*" -print

Find within the directory "/home/john/", all files (-type f) whose name start with "pl".

find dirname options -exec command {} \;

Note : "-exec command {} \;" means "apply command to those found".
"{}" stands for those found, and "\;" signifies the end.

find /home/tom/ -type f -name "*bak" -size +5000k -print -exec rm {} \;

Find within the directory "/home/tom/", all files (-type f) whose name end with "bak" and whose size is greatter than 5000k, and then remove them.

For more details about "find", please use "man find" command to read the online manual about "find".

su
[Super User] Some commands may only be executed by the super-user, e.g. "mount" command. After typing this command "su", we will be asked the password of super-user, and after that, we may execute those "privileged commands". To quit "super-user" mode, type "exit".

Recurrsive copy or move

Sometimes we wish to move/copy everything within a directory (including subdirectories within it) to another directory, then we may use the "-r" (recurrsive) options, e.g.
cp -rv /home/tom/ /home/test/
mv -rv /home/tom/ /home/john/
rm -rf /home/tom/
The first will copy everything in directory "/home/tom/" to "/home/test/". (options = recurrsive and verbal)

The second will move everything in directory "/home/tom/" to "/home/john/".

The third will remove everything in directory "/home/tom/" (options = recurrsive, forced)

When a program fails, usually the system will do a "core dump", and a file "core" will be generated. This file "core" is rather large, and you may delete it.

Pascal, Fortran

There is a "pascal to C" program in LINUX, called "p2c"

p2c filename.pas
gcc -Wall filename.c -lp2c

The first command will change a file whose extension is ".pas" to a C program, e.g. "myprog.pas" will produce "myprog.c". Then we have to compile this C program with gcc. Note that we need a library "libp2c.a".

There is also a "Fortran to C" program in LINUX, called "f2c"

f2c filename.f
gcc -Wall filename.c -lf2c

The first command will change a file whose extension is ".f" to a C program, e.g. "myprog.f" will produce "myprog.c". Then we have to compile this C program with gcc. Note that we need a library "libf2c.a". But usually there is a "f77", or "fort" that combines these 2 steps into one.

For more details, you may read the online manual, e.g. "man f2c", "man p2c".

More about Backup

(You may omit this)

If everything is under "/home/", then we just back up this directory.

For incremental backup, we may write a shell script, e.g.

      tarfile = /tmp/backup.gz
      tarlist = /tmp/backuplist
      echo "Which directory to back up ? "
      read dirbk
      echo "Backup files accessed during the last m days. m ?"
      read days
      cd $dirbk
      find $dirbk -type f -mtime -$days -print > $tarlist
      tar cvzf $tarfile `cat $tarlist`

There is also a "cpio" command to do backup, e.g.

      ls | cpio -ov > /tmp/backup.cpio
           (This  "lists" all files in the current directory, 
            and "pipe" the names to the program "cpio" for backup.  
            "-o -v" options mean "outwards, verbose". 
            And the output file is /tmp/backup.cpio)

      cpio -i < /tmp/backup.cpio
           (This command will restore the backup files.  
            Option "-i" means "inwards".)

      find . -mtime 3 -print | cpio -ov > /tmp/backup.cpio
           (Find all files within the current directory which have been 
            modified in the last 3 days and "pipe" them to "cpio" for 
            "outward" backup.)

      cpio -it < /tmp/backup.cpio
           (List the "table of contents" of /tmp/backup.cpio.  
            But restoration of files will not be done.
            Options = "inwards, table of content".)

      cpio -id < /tmp/backup.cpio
           (Restores the files. Options = "inwards, (restore)directory, if
            they have been removed".)

For more details, please read the online manual "man cpio"


Shell (Command Interpreter)

The "shell", or "command interpreter" in LINUX is "bash". You may write "shell scripts" to automate many tasks.

3 files are automatically opened whenever LINUX is booted up : i.e. "stdin" (standard input, which is the keyboard), "stdout" (standard output, which is the screen), "stderr" (standard error, which is also the screen). System will accept commands or output error messages through these.

For more details about "bash", please use "man bash" to view online manual.


Final Remarks

I have covered those commands commonly used in LINUX, and I hope they would be sufficient for the moment for what we intend to do later, i.e. C programming.

They may seem confusing, but I hope you can get the help of an experienced person to give you some "hand on" experience, and demonstrate the steps to you. You will find that to use LINUX would not be as difficult as these web pages suggest.

There are many things in UNIX, and you may read books about them, or read the online manual. (I do not mention the XWindow here, you may use them if you like, but I do not need XWindow for the rest of this online book.)

Unfortunately, LINUX or UNIX are full of virus written by people in the dark, and we really could do no effective work in it (my computer is under remote-control by people in the Secret Alliance). However, C is a language that will give us great insight into computer science, and is worth exploring even we can do no effective work now.


[Previous] [Home] [Next]