Linux Survival Guide

download Linux Survival Guide

of 15

Transcript of Linux Survival Guide

  • 8/3/2019 Linux Survival Guide

    1/15

    Cognasium t/a Telamenta. CK 2007/182367/23

    P.O. Box 432, Bromhof, 2154 Phone: 083-377-4946 Fax: 086-679-5126

    Linux Survival Guide1

    version 0.3

    http://www.obsidian.co.za [email protected]

    P.O.Box 4938, Cresta, 2118 Tel: +27 11 792 6500 Fax: +27 11 792 6522

    1This document and its LATEX source code may be used and distributed under the GNU Public License

  • 8/3/2019 Linux Survival Guide

    2/15

    Contents

    1 Starting with Linux 3

    2 Shell basics 32.1 Logging in, meeting the shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.3 Shell interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.4 Console Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.5 The Standard IO streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    3 Command basics 53.1 The easy way out for DOS addicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2 Files and Directories Drive Letters not welcome . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3.2.1 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2.2 File ownership and Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2.3 Wild-cards (Globbing) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2.4 Other Oddities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2.5 What happened to the drive letters? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    3.3 Commands for Managing Multiple Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.4 Why Commands need the Shell Piping and Redirection . . . . . . . . . . . . . . . . . . . . . 10

    4 Having a Closer Look 114.1 Revisiting the login procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 Fur ther Games Shells Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.3 Commands for a Multi User system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.4 Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    4.5 X Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    5 The File System 135.1 The Root Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.2 The /usr and /var Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    Copyright c1997 Obsidian Systems CC.

    All registered trademarks mentioned are the sole property of their respective owners.

    All rights reserved.

  • 8/3/2019 Linux Survival Guide

    3/15

    1 Starting with Linux

    Linux can be intimidating to the beginner. Initially it seems as if you have instantly forgotten everything youknew about computers and you have to start all over. Fortunately many of the concepts are quite simple. Thethree most fundamental concepts are:

    Linux is file system centric Everything revolves around the file system.

    Linux is a multi-tasking system There is always more than one thing that is happening.

    Linux is a multi-user system Everything that exists and is owned by someone.

    Have phun.

    2 Shell basics

    2.1 Logging in, meeting the shell

    The first thing you will meet when starting to work with Linux is the login prompt. Linux is fundamentally amulti-user system. This implies that the first action you must take is to identify yourself to the system by typingyour user name and your password.

    Once you have logged in, you get a command prompt that can look something like:

    Aleph:$

    This means that you are currently working on a machine called Aleph, that your current directory is yourhome directory (abbreviated by ) and that you do not have super user privileges (indicated by the $ insteadof a #).

    This command prompt is generated by the program that is invoked called the shell. There are many differentkinds of shells available for Linux, each with its own commands and conventions. The default shell on Linuxis the bash shell and we will assume for the rest of this document that you are using bash.

    2.2 Shell commands

    The primary purpose of the shell is to provide an interface to the computer by which you can run otherprograms. Over the years of Unix/Linux development, this has been refined to such an extent that the shellprovides a programming language of its own. On the other hand, there are very few commands built directlyinto the shell. Most actions are implemented as external programs.

    The simplest shell commands are:

    help This gives help on shell commands. Type help to get a list of commands (example. help help).

    cd Change Directory. Changes your current directory. eg. cd /usr/local/src will take you to the(surprise) /usr/local/src directory. A few helpful variations are:

    cd (without any directory) takes you back to your home directory.

  • 8/3/2019 Linux Survival Guide

    4/15

    cd - Takes you to the previous directory you were in.

    cd xxx Takes you to user xxxs home directory.

    logout and exit closes the current shell and logs you out if this it the last shell.

    pwd Prints your present working directory. This might not seem so useful with a proper command promptsetup, but in shells where the current directory isnt displayed, it is essential.

    2.3 Shell interaction

    The next important aspect of the shell is the tools available to simplify your interaction with the shell. As allinteraction with the shell is done by typing, all these tools have the simple purpose of minimizing the number

    of keystrokes you have to make to get something done.

    The most important of these are:

    The TAB key This provides you with command and path completion. When you press the TAB key, the shelltries to figure out what is it that you are trying to type, and completes it for you as far as possible. Wordsbefore the first space on the command line are attempted to be completed as a command, any followingwords are completed as paths in the file system.

    As a test, type nsl[TAB]. That should complete to nslookup, a saving of four keystrokes. Or try cd/v[TAB]sp[TAB]mq[TAB]. That should result in cd /var/spool/mqueue, a saving of 8 keystrokes.When the letters are non-unique when you press tab, the computer will beep once, and the second timeyou press tab it will give you the possibilities. This is an easy way to get a list of all the commands on

    the system. With nothing on the command line, press [TAB] till you get a question and answer yes.

    History All commands you type are saved in the history. You can scroll through the history by using the upand the down arrows. History is saved between sessions, so you can find commands you typed whenyou logged in the previous time. A more advanced functions of the history that is very useful is reversesearching the history. Try typing Ctrl-R and then the start of a command you typed a while ago.

    Aliasing You often have to type a long command over and over. The shell provides an easy way for you tocreate a nickname for that long command. For example on my system, I like to start X-windows withthis command: startx -- -bpp 16. By typing alias x=startx -- -bpp 16 I can then justtype x instead. To get rid of this alias you could then type unalias x.

    Key Bindings Some things are used so often it is useful to have single (or simple composite) keystrokes forthem. Many of these key-bindings are pre-defined (eg. Ctrl-A for beginning of line, Ctrl-E for end, Ctrl-l

    for clear screen, Ctrl-C for clear line and many more). You can also create your own bindings with thebind command.

    Directory Stack Often you are busy working somewhere and you quickly need to check something in anotherdirectory. When you are finished there you have to find the original directory you were working in. Tosolve this problem you have the directory stack. In its simplest form, you can save your current directorywithtt pushd . and later retrieve it with popd. To list the directories currently on the directory stack, typett dirs.

    2.4 Console Features

    Some actions Joe Average computer user wants to perform can not easily be implemented with commands orfrom within the shell. Often you want to work in separate windows even if you have only text mode available, or

  • 8/3/2019 Linux Survival Guide

    5/15

    need to copy information to the command line that is already printed exactly the way you want it on the screen,

    or that vital piece of information just scrolled off the screen. For these kind of problems Linux implementssome useful solutions:

    virtual consoles By pressing alt-f1 to alt-f6 you can switch between virtual consoles. The num-ber of consoles may vary and can be customized. While in X, the same can be done by ctrl-alt-f1etc. To get back to X switch to alt-f7.

    mouse selection Copy a piece of text by pressing mouse button 1 and dragging to the end of the text.Paste the text by pressing mouse button 2 (normally the right one).

    scrolling the screen By pressing shift-page-up and shift-page-down the text that scrolled offthe screen can be revived. The buffer isnt huge but sufficient for most purposes. The buffer is destroyedif you switch between virtual consoles.

    2.5 The Standard IO streams

    Finally before we go on to the basic commands, there is a fundamental concept that is applicable to allprograms running on a Linux/Unix system but is constantly used when working with the shell. Every processis created with 3 open files. These are called:

    Standard Input (stdin) the default source of input data

    Standard Output (stdout) the default destination of any output

    Standard Error (stderr) the default output stream on which to report errors.

    One of the most powerful concepts of Unix/Linux is that these standard data streams can easily be bound toeach other to form pipes of programs. Well get into the details of this later, for now it is enough to know thatthey exist.

    3 Command basics

    Unlike DOS, Linux commands are not usually part of a command interpreter (the shell) but almost alwaysseparate programs. This implies that there is no implicit difference between a Linux command and a user

    program. Linux commands are just the collection of programs that are generally useful and included in mostLinux systems.

    Anything typed on the command line is checked if it is a built-in shell command, if not it is assumed to be anexecutable somewhere on the system. If a corresponding executable is found, it is run with the command linearguments following it.

    Command switches for Linux commands are indicated with a - or sometimes a + and normally come rightafter the command name, before the operands. For example, in DOS the command to list all the files startingwith c in columns would be: dir c*.* /w while the equivalent Linux command would be ls c*

    As a fast start, here is a comparison of DOS and Unix/Linux commands:

  • 8/3/2019 Linux Survival Guide

    6/15

    3.1 The easy way out for DOS addicts

    DOS Linux Notes

    cd cd (Lets start easy :-)rd rmdir Who said Linux is more cryptic than DOS ?md mkdirdir ls For file names

    find Finding filesdf For space on drivedu For space used by files

    cls clear Clear screentype cat Doesnt pause

    more type /p

    less a file browsercopy cp copying filescat concatenating files

    copy file1 file2 file3 = cat file1 file2 file3ren mv doesnt do wild-card renamesdeltree rm -r Be careful !!fc cmp Simple version

    comm Sorted filesdiff Complex versiondiff3 Getting kinky 3 files

    sort sort Some things never changeundelete Oops, this is computing for grownups :-)help man Opens up Linux to the ... pro :-)

    date date Highly configurabletime date As I said . . .

    The following commands are some of the most used commands in Linux as they provide important & usefulinfo. (Most people also type ls when they havent decided what to do next, which makes it probably the mostused command in Linux)

    ls Lists the files in the current directory. Some often used switches:

    -l long format (default is just names)

    -a all files. File names starting with . are hidden and dont show up in normal lists.

    -F add a character to indicate the type of file

    cat Places the contents of a file or files on the standard output. This is initially useful for reading short textfiles (cat README), concatenating files (cat file1 file2 file3 fileall) but can be used in a wide variety ofcircumstances. Try cat /etc/fstab to see the configuration file of the file system.

    more Displays info a screen full at a time. more has been largely replaced by less on systems where it isavailable.

    less Is used to view files in a more controlled fashion. Page up and page down works as expected, you cansearch by typing / and to exit from the viewer you typett q. Two different ways to invoke less is with a file name or with input from the standard input:

    less /etc/sendmail.cf cat /etc/sendmail.cf | less

  • 8/3/2019 Linux Survival Guide

    7/15

    man With man Linux is an open book might be a slight overstatement, but man definitely makes Linux man-

    ageable if not exactly friendly. man subject gives a (sometimes cryptic) description of commands, csystem calls, subroutines, devices, file formats, games, system admin subjects and other miscellaneousfacts of life2.

    find the mother of find programs. Pretty complex and cumbersome but it can search for almost anything.The simplest way of using it is typically find . -iname "foo*" to look for files in this directory andchild directories for files starting with foo.

    3.2 Files and Directories Drive Letters not welcome

    The hierarchical file system is an idea that originated with Unix. It created the concept of a directory that can

    contain both files and other directories. The basic tools for manipulating files and directories are:

    mkdir Make a new directory.

    rmdir Removes a directory.

    cp Copies files. Takes at least 2 arguments. If both are file names it copies file1 to file2, if the second is adirectory the name is kept identical and the file is copied to the directory. If more than 2 arguments arespecified the last must be a directory and all the names files are copied to the directory.

    mv identical to cp but deletes the original file. Note because of shell wild-card expansion the typical DOSconstruct mv *.a *.b will be expanded to something like mv f1.a f2.a xxx.b whatever.b andwill result in an error. The easiest way to do this is by using a sed script.

    rm Removes files. Removes are not recoverable. rm -r foo removes directory foo and all its subdirectory.Should the super user type rm -r * in the root directory the whole system will be deleted without somuch as a are you sure(y/n) you have been warned.

    3.2.1 Links

    The Linux file system is more versatile than the DOS file system. An important extension (or omissionsdepending which way you look) is the concept of a link.

    Often the same file is needed in different places on a disk. Instead of making copies of these files it is possible

    in Linux to create links. Two kinds of links are possible hard and soft (or symbolic) links.

    Hard linked files are indistinguishable from normal files, but a change to one is a change to the other. If twofiles are hard linked one can be deleted without affecting the other seen in another way, you have to removeall hard links to data on a disk before the space is available again. Hard links are only possible between fileson the same partition. Directories can not be hard linked.

    For example, say we have a 10 MB file /home/httpd/hugefile. We need the same file to be in /home/ftp/pubbut called interestingfile. By executing: ln /home/httpd/hugefile /home/ftp/pub/interestingfilewe have two file names, both reported to be 10MB in size but we only use 10MB of space on the hard drive.

    Symbolic links are just pointers to where the real file can be found. If the real file is deleted the pointer stillexists but points to nothing. Symbolic links can span partitions and can link directories. As symbolic links are

    generally more versatile than hard links, they are more often used.2Try man /usr/share/emacs/19.34/etc/sex.6

  • 8/3/2019 Linux Survival Guide

    8/15

    3.2.2 File ownership and Permissions

    As Unix/Linux is a multi-user system, there must be some way for files to belong to certain users and theremust be a mechanism for sharing files amongst users. Furthermore must there be some system by which totell whom can do what with which file.

    To implement this, Unix associates every file and directory with an owner and a group. Three different typesof permission are given to each file read permission, write permission and execute permission. Combiningthese aspects, it is logical that each file or directory has 9 pieces of permission information about it.

    A file permission string typically looks something like -rwxr-xr-- the first dash is space where the type offile is specified (- is a normal file, d for directory, l for symbolic link etc.) then you get three groups of threeentries, a 3 for each of the user, group and other (the rest of the universe). The three dashes in each groupis for readability, writeability and executability. In our example the owner can read, write and execute the file,the group members can read and execute the file and the rest can only read it.

    chown changes the owner of a file or files

    chgrp changes the group a file or files belong(s) to.

    chmod changes file permissions. Typically chmod ugo+rwx foo. For example to give the group writepermission to file foo: chmod g+w foo

    3.2.3 Wild-cards (Globbing)

    Another difference between DOS and Linux is the handling of wild-cards in file names. DOS requires eachprogram that handles file names to be able to expand wild-cards. In Linux the shell is responsible for expand-ing wild cards. Thus in DOS if we say del s*.* the delete program has to find all the files that start withs (say s1 and s2), in Linux the shell expands the file names and rm s* it becomes rm s1 s2 before theremove command is run. Linux also has more wild-card expansions:

    * matches unlimited numbers of all characters

    ? matches one occurrence of any character

    [abcd] matches any one of a,b,c or d

    [abcd] matches anything but a,b,c or d

    [a-z] matches the whole range from a to z

    3.2.4 Other Oddities

    Except for normal files, directories and links, there are a few other file types in Linux. Physical devices arealso represented by files. For example your first serial port is seen as a file /dev/ttyS0. This file can bemanipulated with commands like ln, cat and echo, just like a normal file.

    Another type of file is a named pipe. This is temporary store for data generated by one program and to be

    read by another.

  • 8/3/2019 Linux Survival Guide

    9/15

    3.2.5 What happened to the drive letters?

    One thing glaringly different between DOS and Linux is the absence of drive letters. Because a unix systemmay have many more than 26 physical devices (and many drive letters are confusing to say the least), adifferent type of system is employed. On any unix system one physical device must be specified as the rootdevice. Any number of other divides can then be attached to this file system by mounting the device on anempty directory on an already mounted device.

    For example, if we have an empty directory /mnt/cdrom, we can mount a SCSI cdrom under that directorywith the command:

    mount /dev/scd0 /mnt/cdrom

    Later when the cd must be removed, we can unmount it with umount /mnt/cdrom.

    The power of this system becomes apparent when we realise that the mounting is not limited by physicaldevices only, but you can mount a remote file system (say on machine foo) to look as part of the local filesystem with a command like:

    mount foo:/remote/directory /local/directory

    Mounting and unmounting also takes care of the problem with removable media and multiple users. In ourCD-ROM example the umount would return an error if someone was still using the cd.

    Some commands used in working with disk drives under Linux are:

    mount Attaches a drive to the file system. If the file /etc/fstab is set up correctly mounting can be very simple.eg mount /cdrom, if not pretty hairy eg. mount -t iso9660 /dev/scd0 /cdrom. Remote drivesare easy to mount but it can normally be done only by the su eg. mount kib1:/usr1/linux/redhat/home/ftp/pub/redhat

    umount Detaches a drive from the file system. Very simple in comparison to mount.

    fdformat Low-level formats removable drives (floppies and stiffies).

    sync Most disk transfers under Linux is asynchronous, i.e. it would be possible to remove a stiffy after acopy command has been successful but before the data is actually written to the disk. sync ensures alldisk buffers are flushed. Always sync before unmounting drives or other potentially hazardous actions.

    du Disk utilization. Gives the size (in kb) of the total files in directories.

    df Disk free. Gives statistics of usage on disk mounted on the file system.

    3.3 Commands for Managing Multiple Processes

    Except being a multi user system, Linux allows a single user to run multiple processes at the same time. Tostart multiple processes there are commands for different situations. To handle the processes however theshell must be involved. First we look at the bash interface for multiple jobs.

    & A command followed by & is run in the background.

    Z Pressing Z suspends most programs.

  • 8/3/2019 Linux Survival Guide

    10/15

    fg using fg a suspended program or background job can be brought to the foreground.

    bg changes a process to a background process. A program that has been suspended with Z can be madeto continue in the background using bg.

    jobs describe the current jobs. fg, bg and kill can function with either %jobnumber (eg %1) or the processid number supplied by ps.

    ps lists the processes. Without options it lists just the users processes. To see all the processes use ps -ax.

    pstree graphical representation of processes indicating parentage of processes as well.

    nohup starts a process that will not be terminated when the shell quits (or the user logs out). Works wellonly in conjunction with &

    kill sends a signal to a process identified by its PID or jobnumber. Get the pid with ps. The default signal is

    terminate, which asks a process to clean up and stop. If that doesnt work you can send the KIL L signalusing kill -9 pid

    killall kills all processes running specified commands.

    batch runs a process when the load on the system is low. Takes the commands to run from a file or stdin.

    at schedules a command to be run at a specified time.

    atq prints the list of commands that are to run at later stages.

    atrm removes a command from the at queue.

    crontab program to run commands at scheduled intervals.

    nice sets the scheduling priority of a program.

    renice changes the scheduling priority of a program.

    3.4 Why Commands need the Shell Piping and Redirection

    One of the most powerful aspects of Unix is to string simple commands together to make complex commandsthat can in turn get their information from files and deposit the results into files. This is called piping andredirection.

    Under normal circumstances, the output of one command is written to its standard output. A pipe thenconnects the standard output of that process with the standard input of the next. Either (or both) the initialinput and the final output can be connected to a file called redirection.

    command1 | command2 Pipes the output of command1 to command2.

    command > foo Creates or overwrites file foo and write the stdout of command to foo.

    command < foo Reads stdin from foo. This is the same as cat foo command.

    command >> foo Appends the stdout of command to the file foo.

    command &> foo Redirects both the stdout and the stderr to file foo. There are various other ways ofaccomplishing this. One is important as it is very general: command > foo 2&>1. 2&1 copies

    stream 2 (stderr) to stream 1 (stdout).

  • 8/3/2019 Linux Survival Guide

    11/15

    Say for example we had a list of all the commands in Linux in a file called commands. Now we want to order

    this list and remove any duplicates. We know that there are standard commands called sort and uniq that willdo each of these functions (or at least we know it now ;-), and we want the result to be in sorted.commands.We could do something like:

    cat commands | sort | uniq > sorted.commands

    Simple! Now try doing that in Windows ;-)

    4 Having a Closer Look

    Now we are going to zoom in on a few special aspects we need to understand, or normally need to getworking long before we understand them.

    4.1 Revisiting the login procedure

    OK, so you encounter this Linux system. It looks you in the eye and says:

    Darkstar login:

    But youre armed with your user name and password and boldly type them in. Now the question is: What

    happens next ?

    The program that allows you to log into a unix system is very simple. It checks if the user name and passwordcombination that you supply should allow access into the system (from information it finds in the /etc/passwdfile) and then starts a program called a shell. Your preferred (or enforced) shell is also specified in the

    /etc/passwd directory.

    Your shell can be any program. Sometimes it could be a menu system but mostly it is a command line basedinterpreter. There isnt a standard shell, but there are a number of very widely used ones. Some of the mostfamous are:

    sh The original Bourne shell. This is the grandfather of all shells. It has powerful programming capabilitiesbut the original doesnt support getting access to programs running simultaneously (called job control).

    csh C shell. A very popular shell for human computer interaction but not so popular with shell programmers.The first shell to support job control.

    ksh The Korn shell. A very powerful shell that keeps developing. The newer versions are pretty expensive.

    bash The Bourne Again Shell :-). This is the standard shell from the GNU software suite. The standardchoice on a Linux system.

    The shell you get when you log into the system can be changed with the chsh command.

    4.2 Further Games Shells Play

    An important aspect of working with shells is setting environment variables.

  • 8/3/2019 Linux Survival Guide

    12/15

    It is very easy to set an environment variable, for example to set XXX to hallo you type XXX=hallo. This will

    only be valid for the current shell. In order to make the variable available to all your current shells, you needto export it:

    export XXX

    orexport XXX=hallo

    To get a value for an environment variable interactively, you use the read command: read XXX

    Bash has a complete control language built in. All normal programming structures like for, while and untilloops, if and case statements, functions command line argument parsing. Just to wet your appetite, this codesnippet would find all the files under /etc that contains the word confused and in them change any occurance

    of hallo to goodbye:

    for x in find /etc -type f

    do

    if grep confused $x > /dev/null

    then

    cat $x | sed s/hallo/goodbye/g > /tmp/$$

    cat /tmp/$$ > $x

    echo "Modified file $x"

    fi

    done

    4.3 Commands for a Multi User system

    Linux is designed for multiple users that use the same system. It needs commands to manage security, userinformation and communication between users.

    login Login into the system is usually handled by the program controlling the terminal. A user is asked forhis/her user name and password. When logged in a user starts in his/her home directory where all theusers configuration files are and the user has rights to create files and directories.

    passwd Changes a users pass word. Most systems have certain checks of what constitutes good passwords.

    su Runs a shell with a different user identification. Without a user name assumes root. Root can su todifferent users without supplying passwords.

    groups prints the groups a user belongs to.

    newgrp changes the users current group.

    whoami prints the users login name.

    id prints a summary of identification info.

    chfn changes information about the user stored in the system.

    w prints the users that are currently logged unto the system and what they are doing.

    write sends a message to another user. Write continues until a D or C is entered.

    wall writes to all users on system.

  • 8/3/2019 Linux Survival Guide

    13/15

    4.4 Printing

    Once the printing systems on a Linux system has been set up printing is simple. even to remote printers. Thethree main commands are:

    lpr Print to line printer. Often used as cat try.ps | lpr. Printing is spooled. Different printers andoptions are controlled by command line options.

    lpq Prints the pinter queue.

    lprm Removes a print job from the queue.

    4.5 X Windows

    Starting X is simple, the only question being which X window manager to start. This section also describesthe steps to run X programs on remote machines so that the windows created are displayed on the local Xserver.

    startx This is the command usually used to initiate X. It is set up to start the preferred window manager(on Linux without Motif this is usually fvwm).

    openwin starts the openwindows windows manager, better know to SUN users.

    xsetroot there are many programs that control and customize the look of the X desktop. xsetroot is one

    way of changing the desktop background. This is a good example to play around with to get the feel ofX configuration utilities.

    starting remote X clients To start a X client on machine farstar so that the display is on the localmachine gaia the following steps must be performed (either manually or automated):

    4.1 start an xterm

    4.2 Give farstar permission to display on the gaias X server. The simplest (insecure) way of doing thisis to run xhost +farstar

    4.3 telnet, rlogin or rsh to farstar

    4.4 set the DISPLAY variable to gaia:0. Using sh or bash this is done with DISPLAY=gaia:0;export DISPLAY or on csh by set DISPLAY gaia:0

    4.5 Run the X program simple :-)

    5 The File System

    Outlay of the basic Linux file system:

    All directories, files, links and devices have the same origin: the root directory /

    5.1 The Root Directory

    In the root directory are number of standard directories:

  • 8/3/2019 Linux Survival Guide

    14/15

    /bin contains the binaries for the programs necessary to get the system up and running. Most of the binaries

    are located in /usr/bin but while starting up the system, is is possible that /usr isnt available yet. (Oftenthe /usr drive is mounted from some remote computer).

    /dev contains special files that link the file system with the hardware devices.

    /etc contains system configuration files. The file control the behavior of most of the standard system func-tions, the system startup, networking and hardware configurations. The /etc directory can have a num-ber of sub directories for grouping collections of files for specific purposes. For example on a typicalLinux system /etc can have the following directories:

    rc.d Files that are executed when the system boots, is shut down or changes its run level.

    skel Files that should be copied to the home directory of each new user thats created.

    lilo.conf Linux loader configurations.

    fstab the file describing which devices are mounted where at boot time

    /home is where all the users of the systems have their personal directories where they can create files andsubdirectories. This directory is often interlinked, cross mounted and generally mangled.

    /lib is where the dynamically linked libraries needed for the basic system are kept. As all system programsneed some of these its a bad idea to delete any files in here unless you really know what youre doing.

    /sbin is super user (also called root) territory. Programs that are necessary to get the system running, butshould only be used by root is kept here.

    /tmp is temporary work space available to all users of the system. You shouldnt put any files here howeveras the system has authority to delete anything in here. /tmp is meant to be used by programs only.

    /lost+found is where bad files go :-) If the system goes down unexpectedly and a file position is lost butnot the contents, it is placed in lost+found. This doesnt happen regularly but if you lose something, youknow where to look. Every Linux file system that can be mounted somewhere has its own lost+founddirectory.

    /mnt All file systems that you want to use on a unix system has to be mounted somewhere. /mnt is a placewhere you can mount a file system temporarily.

    /root is the home directory of the super user. This isnt part of the general /home directories as they couldpossible not be present if something goes wrong.

    /boot is used by LILO on a Linux system. It contains information and programs to boot the system.

    /usr is the rest of the Linux system. All the above directories (except for the /home system) must be onthe root partition of the system. /usr is where the basic system is extended. On small installations /usroften shares the same disk or even partition with the / directory. On larger system or small systemsconnected over a network, the detachability of the /usr system leads to more flexibility. The outlay of the

    /usr directory will be detailed in the next section.

    /var If /usr directories are shared across networks, there are some files that should be local to the machinebeing used, either because of differences in hardware or preference. These files are kept in the /vardirectory. Other files kept in the /var directory are files that would normally be in the /usr directory buthave been extensively of frequently customized. The files are then symbolically linked tot eh correctplaces in the /usr directory structure. This means that when the data on a machine is backed up, the

    /usr directory has to me backed up less frequently, as most modifications are done in the /var directory.Large parts of the the /var directory structure mirror the structure of the /usr directory.

  • 8/3/2019 Linux Survival Guide

    15/15

    5.2 The /usr and /var Directories

    A number of subdirectories in the /usr directory are direct counterparts of the directories in the root. Theseare:

    bin for binaries of programs and utilities.

    etc for general program configuration files. Very few programs use this directory.

    lib are the dynamic libraries used by programs.

    sbin are binaries intended for use by the super user only.

    Then there are directories that share system resources:

    src keeps the source code of the programs installed on the system. Often the binaries installed by the systemdistribution doesnt contain the source code but there are still some files in src that is used to make partsof the program like configuration files.

    man the manual pages of the system is kept in the man directory in subdirectories named man1, man2 etc.These manual pages are in source code format and you need the man command to read them. Onceformatted, the formatted text is stored in the cat1 cat2 etc. directories.

    include are the programming include files that are needed to compile new applications or to write your owncode that makes use of libraries.

    doc contains various forms of documentation.

    info contains documentation in the gnu-info format that is readable using the info program of the emacseditor.

    share contains information that can be directly shared across platforms. At this stage it is suspiciously empty.

    dict, dll are directories used by development programs that creates information that is shared by applicationsdeveloped by them.

    All programs and applications that need more files for it in order to run creates files and directories in /usr/libto store this information. It is sometimes said that the order in the rest of the Linux directory tree is just to hidethe chaos in /usr/lib :-)

    One very important directory in usr is the local directory. It is virtually a clone of the /usr system, but is usedto manually install new programs and application. This implies that when the operating system is upgraded,everything is /usr that is not in /usr/local can be replaced without loss, and everything in /usr/local should beable to work like usual with a new system (provided the programs are compatible).

    Some huge programs have their own directories in /usr where they replicate the basic /usr structure just forthe specific program. Examples of these are the X windows system (currently X11R6 in /usr/X11R6), theopenwindows extensions to X (in /usr/openwin). All games are collected in a similar directory (/usr/games).

    The var directory contains some directories that were originally part of usr but are now permanently in var.

    200826-1185-0