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 Windows 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>


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

Now you can refer to g77manual.txt instead of /usr/doc/g77/DOC. Links appear like this in directory listings:

$ ls -F
$ ls -l
(various things...)           g77manual.txt -> /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 in turn 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 its owner's privileges. Typically, you'll come across root suid files.

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


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


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 Initialisation), 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, you do:

$ telnet

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 be the remote X computer and be your Linux machine. To run from an X program that resides on, do the following:

Et voila! Now progname will start on and will be displayed on your machine. Don't try this over a ppp line though, for it's too slow to be usable.

Previous Next Contents