Previous Next Contents

2. Files and Programs

2.1 Files: Preliminary Notions

Linux has a file system---meaning by that ``the structure of directories and files therein''---very similar to that of DOS. Files have filenames that obey special rules, are stored in directories, some are executable, and among these most have command switches. Moreover, you can use wildcard characters, redirection, and piping. There are only a few minor differences:

You can now jump to Section Translating Commands from DOS to Linux, but if I were you I'd read on.

2.2 Symbolic Links

Unix has a type of file that doesn't exist under DOS: the symbolic link. This can be thought of as a pointer to a file or to a directory, and can be used instead of the file or directory it points to; it's similar to Win 95 shortcuts. Examples of symbolic links are /usr/X11, which points to /usr/X11R6; /dev/modem, which points to either /dev/cua0 or /dev/cua1.

To make a symbolic link:

$ ln -s <file_or_dir> <linkname>

Example:

$ ln -s /usr/doc/g77/DOC g77manual.txt

Now you can refer to g77manual.txt instead of /usr/doc/g77/DOC.

2.3 Permissions and Ownership

DOS files and directories have the following attributes: A (archive), H (hidden), R (read-only), and S (system). Only H and R make sense under Linux: hidden files start with a dot, and for the R attribute, read on.

Under Unix a file has ``permissions'' and an owner, who belongs to a ``group''. Look at this example:

$ ls -l /bin/ls
-rwxr-xr-x  1  root  bin  27281 Aug 15 1995 /bin/ls*

The first field contains the permissions of the file /bin/ls, which belongs to root, group bin. Leaving the remaining information aside (Matt's book is there for that purpose), remember that -rwxr-xr-x means (from left to right):

- is the file type (- = ordinary file, d = directory, l = link, etc); rwx are the permissions for the file owner (read, write, execute); r-x are the permissions for the group of the file owner (read, execute); (I won't cover the concept of group, you can survive without it as long as you're a beginner ;-) r-x are the permissions for all other users (read, execute).

This is why you can't delete the file /bin/ls unless you are root: you don't have the write permission to do so. To change a file's permissions, the command is:

$ chmod <whoXperm> <file>

where who is u (user, that is owner), g (group), o (other), X is either + or -, perm is r (read), w (write), or x (execute). Examples:

$ chmod u+x file

this sets the execute permission for the file owner. Shortcut: chmod +x file.

$ chmod go-wx file

this removes write and execute permission for everyone but the owner.

$ chmod ugo+rwx file

this gives everyone read, write, and execute permission.

# chmod +s file

this makes a so-called ``setuid'' or ``suid'' file---a file that everyone can execute with root privileges.

A shorter way to refer to permissions is with numbers: rwxr-xr-x can be expressed as 755 (every letter corresponds to a bit: --- is 0, --x is 1, -w- is 2, -wx is 3...). It looks difficult, but with a bit of practice you'll understand the concept.

root, being the so-called superuser, can change everyone's file permissions. There's more to it---RMP.

2.4 Translating Commands from DOS to Linux

On the left, the DOS commands; on the right, their Linux counterpart.

COPY:           cp
DEL:            rm
MOVE:           mv
REN:            mv
TYPE:           more, less, cat

Redirection and plumbing operators: < > >> |

Wildcards: * ?

nul: /dev/null

prn, lpt1: /dev/lp0 or /dev/lp1; lpr

- EXAMPLES -

DOS                                     Linux
---------------------------------------------------------------------

C:\GUIDO>copy joe.txt joe.doc           $ cp joe.txt joe.doc
C:\GUIDO>copy *.* total                 $ cat * > total
C:\GUIDO>copy fractals.doc prn          $ lpr fractals.doc
C:\GUIDO>del temp                       $ rm temp
C:\GUIDO>del *.bak                      $ rm *~
C:\GUIDO>move paper.txt tmp\            $ mv paper.txt tmp/
C:\GUIDO>ren paper.txt paper.asc        $ mv paper.txt paper.asc
C:\GUIDO>print letter.txt               $ lpr letter.txt
C:\GUIDO>type letter.txt                $ more letter.txt
C:\GUIDO>type letter.txt                $ less letter.txt
C:\GUIDO>type letter.txt > nul          $ cat letter.txt > /dev/null
        n/a                             $ more *.txt *.asc
        n/a                             $ cat section*.txt | less

Notes:

2.5 Running Programs: Multitasking and Sessions

To run a program, type its name as you would do under DOS. If the directory (Section Directories) where the program is stored is included in the PATH (Section *System Initialization), the program will start. Exception: unlike DOS, under Linux a program located in the current directory won't run unless the directory is included in the PATH. Escamotage: being prog your program, type ./prog.

This is what the typical command line looks like:

$ command -s1 -s2 ... -sn par1 par2 ... parn < input > output

where -s1, ..., -sn are the program switches, par1, ..., parn are the program parameters. You can issue several commands on the command line:

$ command1 ; command2 ; ... ; commandn

That's all about running programs, but it's easy to go a step beyond. One of the main reasons for using Linux is that it is a multitasking os---it can run several programs (from now on, processes) at the same time. You can launch processes in background and continue working straight away. Moreover, Linux lets you have several sessions: it's like having many computers to work on at once!

2.6 Running Programs on Remote Computers

To run a program on a remote machine whose IP address is remote.bigone.edu, you do:

$ telnet remote.bigone.edu

After logging in, start your favourite program. Needless to say, you must have an account on the remote machine.

If you have X11, you can even run an X application on a remote computer, displaying it on your X screen. Let remote.bigone.edu be the remote X computer and local.linux.box be your Linux machine. To run from local.linux.box an X program that resides on remote.bigone.edu, do the following:

Et voila! Now progname will start on remote.bigone.edu and will be displayed on your machine. Don't try this over a ppp line, though.


Previous Next Contents