Next Previous Contents

4. Files and Programs

4.1 Files: Preliminary Notions

Linux has a structure of directories and files very similar to that of DOS/Win. 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.

4.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 shortcuts. Examples of symbolic links are /usr/X11, which points to /usr/X11R6; /dev/modem, which points to either /dev/ttyS0 or /dev/ttyS1.

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. Links appear like this in directory listings:

$ ls -F
g77manual.txt@
$ ls -l
(several things...)           g77manual.txt -> /usr/doc/g77/DOC

4.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, 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).

The directory /bin has permissions, too: see Section Directories Permissions for further details. This is why you can't delete the file /bin/ls unless you are root: you don't have the 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). Common examples of chmod use are the following:

$ chmod +x file

this sets the execute permission for the file.

$ chmod go-rw file

this removes read and write 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; these are often important system files, like the X server.

A shorter way to refer to permissions is with digits: 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 superuser, can change everyone's file permissions. RMP.

4.4 Files: Translating Commands

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

ATTRIB:         chmod
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>ATTRIB +R FILE.TXT             $ chmod 400 file.txt
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:

4.5 Running Programs: Multitasking and Sessions

To run a program, type its name as you would do under DOS. If the directory (Section Using Directories) where the program is stored is included in the PATH (Section System Initialisation Files), 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!

Using these commands you can format a disk, zip a bunch of files, compile a program, and unzip an archive all at the same time, and still have the prompt at your disposal. Try this with Windows, just to see the difference in performance (if it doesn't crash, of course).

4.6 Running Programs on Remote Computers

To run a program on a remote machine whose name is remote.machine.edu:

$ telnet remote.machine.edu

After logging in, start your favourite program. Needless to say, you must have a shell 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.machine.edu be the remote X computer and let local.linux.box be your Linux machine. To run from local.linux.box an X program that resides on remote.machine.edu, do the following:

Et voila! Now progname will start on remote.machine.edu and will be displayed on your machine. Don't try this over the modem though, for it's too slow to be usable. Moreover, this is a crude and insecure method: please read the ``Remote X Apps mini-HOWTO'' at http://www.linuxdoc.org/HOWTO/mini/Remote-X-Apps.html.


Next Previous Contents

mirror server hosted at Truenetwork, Russian Federation.