Site hosted by Angelfire.com: Build your free website today!

 

 

Floppix - Linux on 2 floppies


Floppix

derived from:

Debian/GNU Linux

hosted by:

CCAI

Floppix is a teaching tool; it is a very small subset of Debian/ GNU Linux that fits on two 3.5" 1.4Mb diskettes. The current version is derived from Debian 2.1 (slink), copyright under the GNU GPL "copyleft". It provides a platform to practice linux commands and experiment with simple system administration.

Floppix has no hard drive support; you cannot access, modify, damage or destroy anything installed on the hard drive. For this reason, Floppix works safely in the lab, at home or at work.

Floppix runs from a RAMDISK. Since the entire filesystem is stored in RAM, all changes are lost when the system is shutdown or rebooted. This makes it possible to experiment freely; if you want (or need) to start over, all you have to do is reboot. For example, if you want to know what is left after the superuser has deleted the entire filesystem, Floppix is the place to try it.

Floppix works in our environment but it comes with no guarantees. Caveat hacker. Send comments and corrections to L.M.MacEwan; send complaints to /dev/null.

Copyright © L.M.MacEwan

 

 

READ THIS: 

 

How Floppix Works for PVCC Students

 

1.      Boot the computer with the DOS disk

 

  1. Insert Linux Disk 1 (Floppix refers to this as the “boot disk”)

 

3.      At the a: prompt type:  loadlin linux

 

4.      When it is done loading linux disk 1, it will prompt you to put in linux disk 2.  Do that.

 

5.      Finally, you will be prompted to put in linux disk 1 again (the “boot disk”).  Do that.

 

HINT:  While loading Floppix, you will be prompted to enter your name, initials, and password.  Make the information something you can remember. 

 

To get into Linux via Floppix, you will be prompted for your Login.  Your login is your initials.  Your password is whatever you set your password to be.  If you forget your login/password, you have to reboot into DOS and start all over again with the disk switching! 

 

 

Now you can use Floppix on any PC!!!!

 

Do not damage or lose the DOS disk, and the two Linux disks (1 and 2).   

 


 

Frequently asked questions:


A.  What is included in floppix?

  • Floppix provides a platform to practice Unix commands and basic system administration. As much as possible, Floppix behaves like a small Debian installation. It includes:
    1. the bash and flin shells, user and root accounts, 3 virtual consoles
    2. unix utilities: find, grep, cut, vi, tr, sed, awk, sort, wc, gzip, tar, diff , lpr ...
    3. network configuration for fixed IP, dhcp, ppp
    4. network utilities: ping, telnet, ftp, mail, ssmtp, fetchmail, links, ssh, ipfwadm, traceroute, host, netstat
    5. daemons: inetd, tcpd, telnetd, ftpd, icmplogd, tcplogd, klogd, syslogd, cron, lpd
    6. Debian system initialization setup with S and K scripts and runlevels
    7. support for ext2, msdos and vfat filesystems on floppy diskettes
    8. mount, mke2fs, e2fsck, umount, smbmount, smbumount, du, df, dd, stat
    9. system logs (on tty8)
    10. simulated man pages
       
  • Floppix can be used safely because ALL hard drive support is disabled.
     
  • For the most part the commands are taken directly from Debian 2.1 with these exceptions:
    1. email is handled by a script that determines whether the mail should be delivered locally or forwarded to an SMTP server
    2. man is a script and the man pages are usually the internal help for each command.
    3. date is not the real date command; it does not deal with timezones or support any options.

B.  What are the system requirements for floppix:

  1. At least a 486DX with a 3.5" floppy and 16Mb RAM.
  2. A network card is NOT required. The supported network cards are: 3c503, 3c509, 3c905, DEC21*4*, NE2000 (PCI), SMC Ultra, Via-Rhine.

C.  Are there instructions for making a mini-distribution?

The instructions for creating a floppy based version of Linux are available from the Bootdisk HOWTO at the Linux Documentation Project.

D.  Are there other mini-distributions?

There are many floppy based distributions of Linux and more appear each month; each distribution has different goals. Some of my favourites are:

  1. tomsrtbt The most Linux on one floppy; a single disk Linux that can work as a rescue disk.
  2. Linux Router Project a Linux router on one disk
  3. LOAF Linux on a floppy
  4. muLinux a single disk Linux with Internet applications and ppp support
  5. Trinux: A Linux Security Toolkit

E.  Can you suggest other Online Linux/Unix courses?

  1. UNIXHelp: Information for users of the UNIX operating system, developed at the University of Edinburgh from work funded by the ITTI. UNIXhelp is mirrored around the world and freely available for local installation.

  1. Basic Linux Training: A free online course aimed at the DOS/Windows 95 user.

  1. USAIL - Unix System Administration Independent Learning: An excellent course from Indiana University.

  1. 85321 Systems Administration: an online system administration course from Central Queensland University.

F.  Can you recommend a linux textbook?

  1. Everything from the Linux documentation project.
    For the Floppix labs, which are setup for the beginner, I particularly recommend Linux Installation and Getting Started

  1. Learning the UNIX Operating System, 4th Edition
    By Jerry Peek, Grace Todino & John Strang
    ISBN: 1-56592-390-1, published by O'Reilly
    This book is about 100 pages and deceptively simple. It provides a quick and painless introduction to unix.

  1. Running Linux, 3rd Edition
    By Matt Welsh, Matthias Kalle Dalheimer & Lar Kaufman
    ISBN: 1-56592-469-X, published by O'Reilly
    This book a classic. It is not recipe book but you will not find a better overall introduction to all aspects of Linux.

  1. A Practical Guide to Linux
    by: Mark Sobell
    ISBN: 0-201-89549-8, published by Addison-Wesley
    A very thorough comprehensive introduction to user-level Linux.

  1. LINUX® For Dummies® Quick Reference, 2nd Edition
    By Phil Hughes
    ISBN: 0-7645-0422-3, published by IDG
    Phil Hughes is the publisher of the Linux Journal and not a dummy. Make sure that you get the quick reference!

  1. A-Z of Linux, 1st edition
    Phil Cornes, Staffordshire University
    ISBN: 0-13-742867-7, published by Prentice Hall
    60% of this text covers programming under Linux but even if you are not a programmer, the first 40% has wonderful clear conceptual explanations.

Copyright © L. M. MacEwan

 


 

Floppix - Download


System Requirements:

  1. At least a 486DX with a 3.5" floppy and 16Mb RAM.
  2. A network card is NOT required. The supported network cards are: 3c503, 3c509, 3c905, DEC21*4* (Tulip), NE2000 (PCI), SMC Ultra, Via-Rhine.

Instructions for making floppix from Windows 95:

  1. Download floppix.exe and store it in a temporary directory (download links are at the end of this page).
  2. Format 2 floppy diskettes - do a full format and make sure that there are no bad sectors. Do NOT skip this step even if your diskettes are preformatted.
  3. Run floppix.exe to unpack the installation files.
  4. Run install.bat to create floppix diskettes.

Creating floppix from linux:

Floppix wasn't designed for people who already know Linux. However, for those who requested it:

  1. Download floppix.tar.gz. (download links are at the end of this page).
  2. tar  -xvzf  floppix.tar.gz
  3. cd floppix
  4. dd if=disk1.img of=/dev/fd0 bs=1k
  5. dd if=disk2.img of=/dev/fd0 bs=1k

Loading floppix:

Method 1:  For systems that will boot from the floppy (available starting with the current release)

  1. Put disk 1 in the floppy drive and reboot the system. The linux kernel will be loaded into RAM. A screenful of messages will appear as the Linux kernel performs a set of hardware detection routines. Wait for the prompt:
    "VFS:  Insert root floppy disk to be loaded into ramdisk and press [Enter]"
  2. Insert disk 2 and press [Enter]. Wait for the prompt:
    "Please insert boot disk (disk 1); Press [enter] when ready"
  3. Switch back to disk 1 and press [Enter].

Method 2:  For systems in computer lab environments which have Win 95/98 loaded and are configured to boot only from the hard drive.

  1. Shutdown Windows 95 and restart in ms-dos mode. Insert disk 1 and switch to the a: drive. Type: loadlin linux
  2. Wait for the prompt:
    "Insert the floppy disk for loading into RAMDISK"
  3. Insert disk 2 and press [Enter]. A screenful of messages will appear as the Linux kernel performs a set of hardware detection routines. Wait for the prompt:
    "Please insert boot disk (disk 1); Press [enter] when ready"
  4. Switch back to disk 1 and press [Enter].

Potential problems:

  • CRC error messages during the boot process indicate that your diskettes are bad. Even if floppix appears to boot it will not work. Try formatting the diskettes again and re-installing floppix. If this doesn't work, start buying a different brand of diskettes.
  • If floppix boots and gives the error message:
    "kernel panic: VFS: Unable to mount root fs on 02:00"
    either disk 2 is bad or you didn't switch to disk 2 at the RAMDISK prompt.
  • Some BIOS's cannot correctly report the amount of installed memory on systems with more than 64M of RAM. On these systems, floppix will appear to boot and then fail. In this case, you must start floppix with the command: "loadlin linux mem=xxxM" where xxx is the actual number of megabytes of memory installed.
  • The linux kernel as compiled for floppix requires a math co-processor. Floppix will not work on older 486 laptops based on an SLC processor.

Download current version (2.1r4): April 12, 2000

For DOS/Windows users:

  • floppix.exe using http (with some browsers you will have to right-click on the link)

For linux users:

Copyright © L. M. MacEwan


 

A Beginner's Introduction to Command-line Linux

introduction:
1. getting started
2. running commands
3. logical organization of the linux filesystem
4. navigating the filesystem

file and directory commands:
5. directory listings
6. directory commands
7. file commands

creating, saving, printing
8. a very brief introduction to vi
9. saving your files from floppix
10. printing

searching for files:
11. find
12. grep

other users
13. who's on floppix?

redirection, pipes and filters:
14. redirection
15. pipes and filters

managing your account:
16. passwords and permissions
17. umask
18. the search path
19. configuring your account
20. configuring the bash shell
21. process management

working on the Internet:
22. e-mail
23. telnet
24. ftp
25. links: a text web browser

scripting:
26. basic bash scripts

working as superuser:
27. superuser

adding users and groups
28. adding users
29. working with groups

system startup and shutdown:
30. runlevels
31. hardware detection
32. init and inittab
33. rc.d directories

managing the filesystem:
34. format, check, mount
35. archiving and compressing

scheduling:
36. cron

system logs:
37. monitoring system logs
38. configuring syslogd

security:
39. setuid, setgid programs
40. tcpd
41. inetd

Copyright © L. M. MacEwan

 


1. Getting Started


Notes:


Instructions for Loading floppix:

Method 1: With version 2.1r3, you can boot directly from disk 1 (this was not available in previous versons)

  1. Put disk 1 in the floppy drive and reboot the system. The linux kernel will be loaded into RAM. A screenful of messages will appear as the Linux kernel performs a set of hardware detection routines. Wait for the prompt:
    "VFS:  Insert root floppy disk to be loaded into ramdisk and press [Enter]"
  2. Insert disk 2 and press [Enter]. Wait for the prompt:
    "Please insert boot disk (disk 1); Press [enter] when ready"
  3. Switch back to disk 1 and press [Enter].

Method 2:  For systems in computer-lab environments which have Win 95/98 loaded and are configured to boot only from the hard drive.

  1. Shutdown Windows 95 and restart in ms-dos mode. Insert disk 1 and switch to the a: drive. Type: loadlin linux
  2. Wait for the prompt:
    "Insert the floppy disk for loading into RAMDISK"
  3. Insert disk 2 and press [Enter]. A screenful of messages will appear as the Linux kernel performs a set of hardware detection routines. Wait for the prompt:
    "Please insert boot disk (disk 1); Press [enter] when ready"
  4. Switch back to disk 1 and press [Enter].

Potential problems:

  • CRC error messages during the boot process indicate that your diskettes are bad. Even if floppix appears to boot it will not work. Try formatting the diskettes again and re-installing floppix. If this doesn't work, start buying a different brand of diskettes.
     
  • If floppix boots and gives the error message:
    "kernel panic: VFS: Unable to mount root fs on 02:00"
    either disk 2 is bad or you didn't switch to disk 2 at the RAMDISK prompt.
     
  • Some BIOS's cannot correctly report the amount of installed memory on systems with more than 64M of RAM. On these systems, floppix will appear to boot and then fail. In this case, you must start floppix with the command: "loadlin linux mem=xxxM" where xxx is the actual number of megabytes of memory installed.
     
  • The linux kernel as compiled for floppix requires a math co-processor. Floppix will not work on older 486 laptops based on an SLC processor.

Answering setup questions after floppix boots:

Because floppix is not installed on your hard drive, you will have to answer some configuration questions every time you use it. This is not part of a normal linux boot process. For many of the questions, the default answer is shown in brackets; press [Enter] to accept the default. The questions are as follows:
 

  1. Enter your name. This is not a trick question, enter your real name (or leave it blank if you prefer to be anonymous )
     
  2. Enter your initials - floppix will create an account for you using your initials as the username. The initials should be in lowercase, a maximum of 5 letters and contain no special characters.
     
  3. Enter a password - make up a password (and don't forget it!). You will have to enter your password twice for verification. Make sure that numlock is on before you use the numeric keypad!
     
  4. You will be given 4 choices for TCP/IP network configuration:
    1. standalone - choose this option if you are unsure
    2. fixed IP (experts only)
    3. dhcp (server-assigned IP address)
    4. dialup connection (limited support - note: a winmodem is NOT a modem)
       
  5. If you configured TCP/IP networking in the previous step, you will be given 2 choices for mail configuration:
    1. practice only - this allows you to send and receive email on floppix only
    2. practice and real email - for this option, you will have to supply your email address and the names of your outgoing and incoming mail servers.
       
  6. There are 2 prompts for printer configuration.
    1. Do you want do print on a parallel port printer. This cannot be a winprinter.
    2. If TCP/IP networking is configured, you will be given a chance to supply the IP address of a print server. The print server must support the TCP/IP protocol and accept input from the linux printer daemon (lpd).
       
  7. Finally, you may choose whether or not to save your configuration data on disk 1.
    1. If you choose to save the data, you will still be asked the configuration questions the next time you load floppix but your own answers will be shown as the defaults. For example:
      Enter your name: (Apprentice Linux Guru)
      Press [enter] to use the default which in this case would be "Apprentice Linux Guru".
    2. Your passwords are NEVER saved on the diskettes. You will have to re-enter your passwords everytime you reload floppix.
       
  8. At the end of the system initialization stage, your should see some additional startup messages, and finally a login prompt.

Logging in:

  1. When the system initialization scripts finish, you will get a login prompt: Login:
    Type your username (in lowercase) and press [enter].
     
  2. The system will display a password prompt: Passwd:
    Type your password (this is the password you created while floppix was loading) and press [enter].
     
    Note: Nothing appears on the screen as you enter the password; this is disconcerting for Windows users who are accustomed to seeing *'s appear; however, it is more secure.
     
  3. If the username and/or password are incorrect, the system will display the message:  Login incorrect and then display the login prompt again. You have a chance to start again. Note that you will have to re-enter both your username and your password.
     
  4. Once you have successfully entered your username and password, the system will display the contents of the motd (message of the day) file. Then you will get a mail notification, informing you whether or not there are any e-mail messages. Finally, you should get a command prompt: $

Logging Out:

  1. To logout, enter the command: logout
     
  2. Logging out does not shut the server down, it just ends your terminal session. You can login and logout as many times as you want.

Virtual Consoles:

  1. When you are logged into a unix system, many other users will be logged in at the same time, all doing their own activities. You can completely ignore the other users, or send them messages. If the system response time is slow, you can use the who command to see how many other users are logged in and the w command to see what each user is doing. If you are working on a stand-alone floppix system, you cannot get the same multi-user experience, but you can get some sense of it by using virtual consoles.
     
  2. Floppix supports 3 virtual consoles: [Alt][F1] activates console 1; [Alt][F2] activates console 2; [Alt][F3] activates console 3.
     
  3. You have to login on each virtual console; you may login using the same username 3 times or 3 different usernames.
     
  4. You may use the virtual consoles for many things. For example, you can work on a different task in each console. Or you can login as a different user on each console to test various configuration options.

Shutting down:

  1. Logout on each virtual console.
     
  2. Press [ctrl][alt][del] to reboot. This will cause the system to shutdown in an orderly fashion.


Exercises:


  1. Load floppix and answer all of the startup configuration questions.
     
  2. Login using your own initials.
     
  3. Read the motd. Is this message entirely in uppercase?
     
  4. Do you have any email messages?
     
  5. What is your command prompt?
     
  6. Logout and then login as alterego (the username is alterego ; all accounts use the same password).
     
  7. Did alterego get the same motd?
     
  8. Does alterego have any e-mail messages?
     
  9. What is the command prompt for the alterego account?
     
  10. Are there any other differences between your account and the alterego account?

 

 

  1. Logout.
     
  2. Try to login again as alterego but this time enter the username in uppercase (ALTEREGO) and the password correctly. This should work, although if you forgot to type ALTEREGO in uppercase the first time, you will have to wait 60 seconds until the login prompt times out and the opening screen is displayed again.
     
  3. Read the motd. Is this message entirely in uppercase?
     
  4. What about the login prompt. Is it in upper or lowercase?
     
  5. Type the logout command. Is it in upper or lowercase?
     
  6. Logout.
     
  7. Login as floopy .
     
  8. What differences do you notice between the floopy account and your own account?
     
  9. Logout.
     
  10. Switch to console 1, then console 2 and then console 3. There is one difference in the login prompts on the 3 consoles.  What is it?
     
  11. Try the following:
    • Login on console 1 using your own initials.
    • Login on console 2 as alterego.
    • Login on console 3 as floopy.
    • Now on console 1, enter the command: who
       
  12. Try this:
    • Switch to console 2 and logout on this console only.
    • Still on console 2, login using your own initials.
    • Now enter the command: who
       
  13. Logout on all consoles.
     
  14. Shutdown.


Questions and Answers:


  1. When you login, does it matter whether you type your username in upper or lower case?
      ; login again.
     
  2. When you login, what appears on the screen as you type your password?
     
     
  3. How many virtual consoles are available on floppix?
     
     
  4. How do you switch to virtual console 2?
     
     
  5. What command ends your login session?
     
     
  6. When you logout, does the server shutdown?

     
  7. Must each account on a unix system be configured identically?
     

  8.  Can the same user be logged in twice on floppix?
     
     
     
  9. Can more than one user be logged in on floppix?
     
     
  10. What does the "who" command display?
     
     

 

2.  Running Commands


Notes:


Entering commands:

Commands must be entered in lowercase. For example:
type: cal and press [return]
This displays a calendar for the current month

Correcting mistakes:

Unix is an old operating system designed to be run on many different types of terminals, some without backspace or delete keys. When you are logging in to a remote system, you may find that the backspace key does not correct your typing mistakes. The following control keys should work on any Unix system:

  1. [Ctrl-h] is the equivalent of the backspace key.
     
  2. [Ctrl-u] erases the entire line.
     
  3. [Ctrl-d] signals end-of-input or end-of-file. Usually when you enter a command, the operating system will execute the command and then display the command prompt again. If the command prompt doesn't re-appear, the system may be waiting for keyboard input; try pressing [ctrl-d] to signal end-of-file.
     
  4. [Ctrl-c] interrupts and cancels the current process. If [ctrl-d] doesn't bring back the prompt, try [ctrl-c].

Command arguments:

Many commands are used with one or more arguments. For example:

  1. cal (no arguments) prints a calendar for the current month.
     
  2. cal 2000 (one argument) prints a calendar for the year 2000.
     
  3. cal 10 2000 (10 and 2000 are both arguments) prints a calendar for October, 2000. 

Command options:

You can also specify options which modify the behaviour of a command. Options appear immediately after the command, they are usually entered as a - followed by a single letter. For example:

  1. cal -j 2000 (j is an option) produces a julian calendar for the year 2000.
     
  2. cal -y (y is an option) prints a calendar for the current year.
     
  3. cal -yj  (2 options) prints a julian calendar for the current year. 

Getting help:

The traditional unix help system is the man command. To get help about the cal command, type: man cal.

Once a man page is displayed, the following commands navigate the document:

  • [SpaceBar] - display the next screen
  • [Enter] - advance 1 line
  • b - go backwards
  • /xyz - search for the string xyz
  • q - quit

Note: on floppix, the man command is only simulated, so the help is often terse and none of the options for the man command are available. 

Command history:

The bash shell saves all of the commands you've entered (up to some pre-defined limit). When you logout, these commands are saved in a file in your own home directory called .bash_history so that the command history is even preserved between login sessions. The command history can be used in a number of ways, but the simplest is to use the up-arrow key to recall previous commands. Once the command is displayed, you can execute it immediately by pressing [enter] or modify the command and then press [enter].

Command completion:

If you are entering long commands or filenames, you seldom have to type the entire string; type enough letters for bash to recognize the text and then press the [tab] key. Bash will fill in the remaining letters for you. If there is more than one option, the shell will beep. Pressing the [tab] key a second time will produce a list of possible matches for the text you have entered.


Exercises:


  1. Load Floppix and login using your initials.
     
  2. Try a few commands:
    • cal (a calendar)
    • date (the date and time)
    • who (a list of everyone who is logged in)
    • cat readme (displays the contents of the readme file)
       
  3. Try entering a command in upper case. For example:  CAL
    What error message is displayed?
    Why?
     
  4. Try the following experiment in using [Ctrl-d] and [Ctrl-c].
    • What happens if you enter "cat" without specifying a filename?
    • Does [Ctrl-d] take you back to the command prompt?
    • Enter the "cat" again.
    • Does [Ctrl-c] take you back to the command prompt?
    • Now, enter the command "sleep 60". This command pauses for 60 seconds.
    • Does [Ctrl-d] take you back to the command prompt?
    • Does [Ctrl-c] take you back to the command prompt?
       
  5. Look at the man page for the who command.
    • what are 3 options for the who command?
    • The who command can accept 2 random arguments. What is output when you enter the command: who am i
    • switch to console 2 and login as alterego.
    • as alterego, what is output when you enter the command: who am i  
    • as alterego, what is output when you enter the command: who likes linux
    • logout on console 2 and switch back to console 1
    • what is output when you enter the command: who likes linux
       
  6. Experiment with command history.
    • Press the [up-arrow] key until you recall the command: who likes linux
    • Do NOT retype the command; modify it to be: who likes linux?
      Press [Enter] to run the command.
    • Press the [up-arrow] key until you recall the command: who likes linux? Modify it to be: who -H likes linux?
      Press [Enter] to run the command.
    • Press the [up-arrow] key to recall the command: who -H likes linux? Press [Ctrl-h] What happens?
    • Press [Ctrl-w] What happens?
    • Press [Ctrl-u] What happens?
    • Press [Ctrl-d] What happens?
       
  7. Try this experiment:
    • Login again.
    • Enter the command: date
    • Logout and login again.
    • View the command history file.
    • Do you start with an empty command history file every time you login or is the history file preserved between sessions?
       
  8. Try using the command completion feature.
    • Enter the command:  ls  /h[tab]
    • What directory name starts with h?
    • Enter the command:  ls   /usr/bin/s[tab][tab]
    • Which filenames in /usr/bin start with s?
       
  9. Logout on all consoles and shutdown.


Questions & Answers:


  1. If you make a mistake while you are entering a line, what combination of keys can you press to erase the entire line and start over?
     
     
     
  2. What key(s) do you press to recall the previous command?
     
     
     
  3. Does the key combination [Ctrl-d] always logout?
     
     
     
  4. What command do you use to get help about the cal command?
     
     
     
  5. Identify the command, options and arguments in the following:
    ls -al /etc
     
     
     
  6. Can commands be entered in uppercase?
     
     usually lowercase.
     
  7. What error message do you get when you try to run a command that does not exist on floppix?
     
     
     
  8. How would you get help on the -j option of the cal command?
     

  9. The syntax for the cal command is:cal [-jy] [[month] year]
    How do you interpret this?
     

 

  1. The syntax for the who command is:who [OPTION]... [ FILE | ARG1 ARG2 ]
    How do you interpret this?
     

 

 

Copyright © L. M. MacEwan

 


 

3.  Organization of the Filesystem


Notes:


When you teleport into your office, it helps to have some idea of the layout of the office complex and the location of your own office in the complex. Eventually you will need to find the necessities of life (such as the coffee machine).

When you login to a linux system, you will be located in your own home directory. It helps to have some idea of the organization of the rest of the file system (especially when you are appointed the system administrator of your own system).

Structure of the logical filesystem:

 
                              /
   +----+-----+----+----+-----+----+-----+-----+----+----+----+
  bin  boot  dev  etc  home  lib  mnt  proc  sbin  tmp  usr  var
                        |                                |
                    +---+---+                        +---+---+
                   abc lmn xyz                      bin lib sbin
                        |
                     +-----+
                   notes  labs

The Linux filesystem is organized in a hierarchical structure starting at the root directory (designated by /) as shown in the figure above.
  

Organization of files in the standard directory structure:

  1. /bin - stores essential binaries (programs) needed when booting the system or working in single user mode to maintain the system
  2. /boot - stores kernel images and boot configuration files
  3. /dev - stores device special files used to access hardware devices
  4. /etc - stores system configuration files
  5. /home - stores the home directories for the individual users
  6. /lib - stores library modules used by the commands
  7. /mnt - a mount point for other storage devices
  8. /proc - a pseudo filesystem for conveying data about processes
  9. /sbin - stores commands  required to administer the system
  10. /tmp - used for temporary files
  11. /usr - used for programs, libraries, documentation, etc used by normal users
  12. /var - stored system data that varies or changes frequently such as system logs, mail and print spool files, etc


Questions and Answers:


  1. In the Linux filesystem, which directory stores system configuration files?
     
     
     
  2. In the Linux filesystem, which directory would store files that are queued for printing?
     
     
     
  3. Suppose you are user "xyz". Where is your home directory in the diagram shown above?
     
     
     
  4. To save space, code that is common to many commands is stored in library files. Which two directories in the filesystem shown above will contain library files?
     
     
     
  5. What is the difference between the / directory which is called the root directory and the /root directory?
     

  6. Help! On my linux system, the logical filesystem is organized differently and my textbook defines things a third way.
     
     
     

Copyright © L. M. MacEwan

 


 

4.  Navigating the Filesystem


Notes:


Path:

  1. An absolute path is the exact location of a file or directory starting from the root directory. For example:
                                                 
                                       
                       / 
           +-----+-----+------+-----+
          bin   etc   home   usr   var
                       |
                  +---------+
                 abc       xyz
                  |
                notes
                                                 

the absolute path to the notes directory is /home/abc/notes . An absolute path always starts with /
 

  1. A relative path gives the location of a file or directory relative to the current directory. If the working directory is /home, then:
    • the absolute path to the abc directory is: /home/abc
    • from /home, the relative path to the abc directory is: abc
    • the absolute path to the notes directory is: /home/abc/notes
    • from /home, the relative path to the notes directory is: abc/notes
       
  2. Some special symbols may be used in relative paths.
    . the current directory
    .. the parent directory
    ~ your own home directory
    If the working directory is /home/abc, then .. is a relative path to /home. 

Commands:

  1. pwd - This command prints the working directory. Use it to find out where you are in the directory tree.
     
  2. cd - This command changes to a specified directory (access to some directories may be denied).
    eg: cd /
    eg: cd /home/xyz
    eg: cd ..


Questions & Answers:


  1. Your home directory is /home/abc
    You enter the command: cd ~
    What is your current directory now?
     
     
     
  2. Your current directory is /home/lmn
    You enter the command: cd .
    What is your current directory now?
     
     
     
  3. Your current directory is /home/lmn
    You enter the command: cd ..
    What is your current directory now?
     
     
     
  4. Your current directory is /home/lmn
    You enter the command:
    cd labs
    What is your current directory now?
     
     
     
  5. Your current directory is /home/lmn
    You enter the command: cd /labs
    What is your current directory now?
     
     
     
  6. Your current directory is /usr
    You enter the command: cd /bin
    What is your current directory now?

     
     
  7. Your current directory is /home/lmn
    You enter the command:
    cd ../..
    What is your current directory now?
     
     
     
  8. Your current directory is /var/spool/mail.
    You enter the command:
    cd ..
    What is your current directory now?
     
     
     
  9. Your current directory is /usr/local/bin/corel.
    You enter the command: cd ../../sbin
    What is your current directory now?
     
     
     
  10. What command(s) give the absolute path to your own home directory?
     
     with a semi-colon

Copyright © L. M. MacEwan

 


 

5.  Directory listings


Notes:


The ls command - examples of common options:
The ls command is used to show the contents of a directory. Some of the options of the ls command are:

  1. ls
    List the contents of the current directory
     
  2. ls   /etc
    List the contents of the /etc directory
     
  3. ls   -a
    Display all entries in the current directory including those beginning with a period. File and directory names that start with a period are "hidden" files in unix; they do not appear in ordinary directory listings.
     
  4. ls   -l
    Display a long or detailed listing of the current directory, one line of data for each entry.
     
  5. ls  -al  /etc
    Display a long listing of the /etc directory including "hidden" files or subdirectories.
     
  6. ls   -h
    The -h option is the "help" option, this gives a list of all of the options for the ls command and brief explanations.
     
  7. To get a list of all of the other options of ls, use the man command. [ man ls ]

Some of the fields in a directory listing entry:

There are a number of things that appear in a unix directory listing:

  1. Permissions:
    Users and the system administrator need a way to control the way other users can access files and directories. The standard unix filesystem does this with permissions. Each file has read, write and execute permisssions set for the owner, the group and then all other users.
     
  2. Links:
    Users can create links to existing files. The filesystem keeps track of the number of links.
     
  3. Owner and group:
    Unix is a multi-user operating system. For each file and directory, the filesystem keeps track of the file owner and group.
     
  4. Size in bytes:
     
  5. Date:
    The unix filesystem actually maintains 3 dates for each file: the last access date, the last modification date (the last date that the file contents were modified) and the last change date (the last date that the file "inode" or directory entry was modified). The date that appears in a standard directory entry is the last modification date.
     
  6. Filename:

A sample directory entry:
       -rwxrw-r-- 1 xyz staff  12 Mar 7 12:35 runme 

  • -   This is an ordinary file
  • rwx   The permissions for the owner (xyz): read, write, execute
  • rw-   The permissions for the group  (staff): read, write, not execute
  • r--   The permissions for others: read, not write, not execute
  • 1   The number of links to the file
  • xyz   The owner
  • staff   The group
  • 12   The size (in bytes)
  • Mar 7 12:35   The last time that the file was modified
  • runme   The name of the file


Exercises:


  1. Load floppix and login using your own initials.
     
  2. In a previous lab, the directory map showed the following directories under /.
    bin, boot, dev, etc, home, lib, mnt, proc, sbin, tmp, usr, var
    Look at the directory listing for the root directory on floppix.
    Are there any directories in the above list that are not present in floppix?

    Are there any top-level directories that are present in floppix and not listed above?

     
  3. Change to the root directory and try to list the contents of each of the top-level directories.
    Which of these directories are empty?
    Ordinary users cannot view the contents of some of these directories.
    Which ones?
    What are the permissions for those directories?
     
  4. What is the purpose of the -F option of the ls command? Look this up using the man pages.
     
  5. Try running the commands:
       ls   -F   /home
       ls   -F   /bin
    What symbol does the -F option use to identify directories?
    What symbol does the -F option use to idenfify executable files?


Questions & Answers:


  1. Interpret this directory entry:
    drwxr-xr-- 2 abc users  1024  Mar 7 12:35 ddd
     
     

 

 

 

Copyright © L. M. MacEwan

 


6.  Directory Commands


Notes:


Some directory commands:

  1. pwd - print working directory (see navigating the filesystem)
     
  2. cd - change directory (see navigating the filesystem)
     
  3. ls - display a directory listing (see directory listings)
     
  4. mkdir - This command creates a new directory. Examples:
    • mkdir sample
    • mkdir /home/abc/sample
       
  5. rmdir -This command removes an existing directory. The directory must be empty before it can be removed. Example:
    • rmdir xxx


Exercises:


  1. Load Floppix and login on virtual console 1 using your own initials.
     
  2. How many directories are stored under /var?
     
  3. Try to view the contents of the directory /sbin?
    What error message is displayed?
    Why?
     
  4. Change to the /var directory. Try to create a directory called ddd.
    What error message is displayed?
    Why?
     
  5. Change to your own home directory and make a directory called ddd there. This time the command should succeed.
     
  6. Cd to the ddd directory and create a file called fff using the command: touch fff
     
  7. Try to make a subdirectory called fff using the command: mkdir fff
    What error message is displayed?
    Why?
     
  8. Still in the ddd directory, try to remove the ddd directory using the command: rmdir ddd
    What error message is displayed?
    Why?
     
     
  9. Change to your own home directory. Try to remove the ddd directory using the command: rmdir ddd
    What error message is displayed?
    Why?
     
  10. Delete the file fff using the command: rm ddd/fff
    Now remove the ddd directory. This time the command should succeed.


Questions & Answers:


  1. What is the command to make a subdirectory called "mine"?
     
     
     
  2. Give 2 situations where the mkdir cmomand will fail?
     

 

  1. Give 2 situations where the rmdir command will NOT remove a directory?
     
     

7.  File Commands


Notes:


Some file commands:

  • more - display file contents one screen at a time. Keystroke commands for more:
    • [SpaceBar] - display the next screen
    • [Enter] - advance 1 line
    • b - go backwards
    • /xyz - search for the string xyz
    • q - quit
       
  • less - a more powerful version of more
     
  • head - display lines from the beginning of a file The default is 10 lines.
    • head -15 /etc/passwd
      displays the first 15 lines of /etc/passwd
       
  • tail - display lines from the end of a file
     
  • cp - copies a file or files
    • cp oldfile newfile
      copies oldfile; the copy will be called newfile
    • cp oldfile newdir
      (assuming newdir is a directory) copies oldfile; the copy will be called oldfile and will be stored in the directory newdir
    • cp f* newdir
      copies all files with a filename beginning with the letter f to the directory newdir; if newdir is not a directory, this concatenates all files beginning with the letter f into a single file called newdir
    • cp f? newdir
      copies all files with two letter filenames where the first letter is f to the directory newdir
    • cp b[aeiu]t newdir
      copies the files bat, bet, bit and but to the directory newdir
       
  • mv - Moves instead of copies
    • the mv command has the same syntax as the cp command
    • the mv command can also be used to rename a file
       
  • rm - This command deletes a file. Examples:
    • rm file1
      delete file1
    • rm *
      delete all files in the working directory
    • rm -i *
      prompt to confirm before deleting each file
       
  • touch - This command changes the access and modification time of a file to the current time. If the file does not exist, touch will create an empty file using that name.
     
  • ln - create a link to an existing file. Examples:
    • ln -s filename linkname
      creates a link or a pointer. The link will be called linkname and it will point to filename.


Exercises:


  1. Load Floppix and login on virtual console 1 using your own initials.
     
  2. Get a listing of the files in your own home directory.
     
  3. What hidden files (filename begins with . ) are present in your own home directory?
     
  4. What hidden files are present in the directory /home/alterego?
     
  5. Use head or tail to do the following:
    • Display the last 4 lines of the file /etc/passwd.
    • Display the last 4 lines of the file /etc/group.
    • Display the first 10 lines of the file /etc/login.defs.
       
  6. Practice the copy command:
    • Copy files in your current directory:
      Make sure that you are in your own home directory.
      Make a copy of readme called readme2. Get a directory listing to make sure that the copy command worked.
      Make a copy of .bash_profile called bprofile. Get a directory listing to make sure that the copy command worked.
    • Copy files from another directory:
      Copy the file called penguin from /home/floopy to your own home directory. Make sure that the copy command worked.
      Copy the file called motd from the /etc directory to your own home directory. Make sure that the copy command worked.
      Copy the file called .plan in the directory /home/alterego to a file called plan in your own home directory. Make sure that the copy command worked.
       
    • Copy files to another directory:
      Copy the readme file to the /tmp directory. As part of the copy, rename the file readme.abc. Get a listing of the tmp directory to make sure that the copy worked.
       
  7. In your own home directory, use the touch command to create five files: one, two, three, four and five. Get a directory listing to make sure that the command worked.
     
  8. Practice making directories.
    • In your own home directory, make 2 subdirectories: dir1 and dir2. Get a directory listing to make sure that the command worked.
    • In dir2, make a subdirectory called dir2a .
       
  9. Practice moving files from your own home directory:
    • Move the file called one to the directory dir1 . Get directory listings of  the source directory and dir1 to make sure that the move command worked.
    • Use a single command and wildcard characters to move all files in your home directory that begin with the letter "t" to dir2 . Get a directory listing to make sure that the move command worked.
    • Use a single command and wildcard characters to move all files in your home directory that begin with the letter "f" to the directory dir2a . Get a directory listing to make sure that the move command worked.
       
  10. Use the move command to rename files.
    • Use the move command to change the name of the file called readme2 to readme.new.
    • Create a subdirectory called aaa.
    • Can you use the move command to change the name of aaa to dir3? _____


Questions & Answers:


  1. What is a "pager"?
     

     
  2. What command will display the last 5 lines of the file /etc/passwd?
     

     
  3. What command will copy the file /etc/passwd to your own home directory?

 

  1. What command will copy all files that start with h from the /etc directory to your own home directory?
     

     
  2. What command will create 3 files: r1, r2 and r3?
     
     
     
  3. What command will copy r1 and r2 to the /tmp directory?
     
     
     
  4. What command will delete the files r1, r2 and r3 but not readme?
     
     

8.  A very brief introduction to vi


Notes:


  1. vi is a powerful text editor; It is one of the standard Unix editors. However, it is also very complex; entire books have been written on vi usage and features.
     
  2. If you do much work on Unix systems, at some time you may have no other option; you will have to use vi.
     
  3. This lab covers a bare minimum of vi commands; enough to perform some very basic tasks.
     
  4. vi was designed to work on a multitude of terminals, many of which had no control keys and no cursor movement keys. So it is possible to use vi using h (left) j (down) k (up) and l (right) keys for cursor movement.
     
  5. vi is a moded editor;
    • in command mode, most keys on the keyboard represent editing commands
    • in insert mode, the keys you press insert text into your document

Using vi:

  1. To start vi, type vi <filename>
     
  2. To get into insert mode and start entering text into the document press:
    • i - to start inserting text before the cursor
    • a - to start inserting text after the cursor
    • I - to start inserting text at the beginning of the current line
    • A - to start inserting text at the end of the current line
    • o - to open up a new line and insert text on the new line
       
  3. To get back to command mode:
    • press [Esc]
       
  4. To delete:
    • make sure you are in command mode; press [Esc]
    • x - deletes the character at the cursor
    • dd - deletes the current line
    • D - deletes from the current postion in the line to the end of the line
    • dG - deletes to end of file
       
  5. To undo a command:
    • u - undo the last command
       
  6. To move a line or block of lines:
    • dd - deletes the line from the current postion
    • p - after moving to the new location; p will put the line(s) after the current line
    • 10dd - deletes 10 lines starting from the current postion
    • p - after moving to the new location; p will put all 10 lines after the current line
       
  7. To copy a line
    • yy - deletes the line from the current postion
    • p - after moving to the new location; p will put the line(s) after the current line
       
  8. To exit:
    • :q! - quit without saving
    • :q - quit
    • :wq - save the file and quit
    • :w - save the file without quitting


Exercises:


  1. Use vi to create a file with the answers to these questions:
    • what is command history?
    • what is command completion?
    • which symbol is used to represent the root directory?
    • what type of files are stored in the /etc directory?
       
  2. Copy the file /etc/passwd to your own home directory.
     
    This file is the user database file. It contains one line for each user; each line contains seven fields separated by colons. The fields are:
    username:password:userid:groupid:name:home_directory:shell
     
    Edit the copy of the password file as follows:
     
    a. Find the line for your account. In this line:
        i. Change the username to joe.
        ii. Change the userid to 500.
     
    b. Find the line for the alterego account.
        i. Change the name to Dr. Freud.
        ii. Change the groupid to 600.
        iii. Change the shell to /usr/bin/flin.
     
    c. Find the line for the floopy account.
        i. Change the password to *.
     
    d. Add a new line: me:*:1004:100:me:/home/me:/bin/bash
     
    e. Delete the line for the games account.
     
    f. Save your work.


Questions & Answers:


For each question, assume that you are editing this file, you are in command mode and the cursor is on line 2, word 2 under the i.


There is a site on the Internet titled:
     Unix is a four letter word and vi is a two letter abbreviation.
The URL for this site is: http://www.linuxbox.com/~taylor/4ltrwrd/


  1. What happens if you type: dd ?
     

     
  2. What happens if you type: xiwa ?
     
     
     
  3. What happens if you type: oC.C.Taylor ?
     
     
     
  4. What command do you use to save the file and quit?
     

  5. What does it mean if you get the error message "File is temporary, exit will discard modifications" when you try to save and quit?
     


9.  Saving your files on a floppy


Notes:


Floppix is configured so that ordinary users can save data on diskettes formatted with a DOS or Windows95 filesystem. There are a few key points to remember:

Linux works with a single logical filesystem, which can actually be stored on several physical devices. For example:

·         the root directory, binaries, libraries and system configuration files may be stored on one hard drive;

·         the home directories for the users may be stored on a second hard drive ;

·         the spool files (mail, print, ... ) may be stored on a 3rd hard drive.

                       / 
           |-----|-----|------|-----|
          bin   etc   home   usr   var
                       |            |
                  |---------|     spool
                 abc       xyz

The system administrator will make sure that all devices are "mounted" (inserted into the logical filesystem) when the system boots. Users can move from their own home directory to the /etc directory to /var/spool without worrying about whether or not they are changing from one drive to another. Normally this gives the system administrator the power to add or change the storage devices transparently - an ordinary user doesn't have to worry about the physical organization of the storage system.

Removable storage devices (such as diskettes and cd-roms) are the fly in the ointment. They cannot be mounted when the system boots because you  may want to change disks several times. Therefore, you must tell the operating system when you insert  or remove a diskette; otherwise, the data will NOT be written on the floppy.

On floppix, you can mount a diskette formatted under DOS or Windows95 on the /floppy directory using the command: mount /floppy. The operating system will check in the configuration file for the mount command (/etc/fstab) to see what device should be mounted (/dev/fd0); what type of filesystem is on the diskette (vfat) and whether or not ordinary users are allowed to mount floppies (on floppix, the answer is yes but normally only the superuser can mount devices).

While the diskette is mounted, any files that you copy to the /floppy directory will be copied to the diskette. After the diskette is “umounted,” the /floppy directory no longer points to the diskette. You can check to see whether or not the diskette is mounted by entering the command: mount. If the floppy is mounted, then the output from mount will be:

/dev/ram on / type ext2 (rw)
proc on /proc type proc (rw)
/dev/ram1 on /usr type ext2 (rw)
/dev/fd0 on /floppy type vfat (rw,nosuid,nodev,user=abc)

As long as the last line (/dev/fd0 on /floppy ... ) is present, then anything you save in the /floppy directory will be saved on the floppy drive. If the line is not present, then you are not writing to the floppy drive.

When you want to eject the floppy, you must tell the operating system before removing the diskette. First, run the sync command. This flushes any data that is stored in the disk cache so that it is physically written to disk. Then, enter the command: umount /floppy. Because linux is a multi-user operating system, the system will check to make sure that none of the users on the system are using the floppy and will NOT unmount the diskette if anyone is using it. If you get the error message: device is busy, then one of the users on your system is still using the diskette. On floppix, that user is probably you! If your working directory is /floppy, then you are still using the diskette and the operating system will not let you unmount it.

Summary: how to save files on a diskette

  • to access a floppy, you must link the diskette to a directory in the filesystem. Use the command: mount /floppy
     
  • cp (copy) the files you want to save to the /floppy directory
     
  • before you eject the diskette
    - flush the disk cache:  sync
    - unmount the disk:  umount /floppy


Exercise:


  1. Find a floppy (blank would be preferable)
     
  2. Insert it in your diskette in the floppy drive but do not mount it.
     
  3. Copy the readme file from your own home directory to /floppy.
     
  4. What files are currently stored in the /floppy directory?
     
  5. Enter the command: mount /floppy
     
  6. What files are shown in the /floppy directory now?
     
  7. Copy the penguin file from /home/floopy to /floppy. Please notice the difference between floopy and floppy!
     
  8. What files are now stored in the /floppy directory?
     
  9. Enter the command: cd /floppy ; sync
     
  10. Try to unmount the floppy. What error message did you get?
     
  11. Enter the cmmand: cd
     
  12. Now try to unmount the floppy. What files are stored in the /floppy directory now?
     
  13. Reboot to your normal operating system and look at your diskette. What is stored on it?


Questions & Answers:


  1. What happens if I forget to mount the floppy diskette and copy files to /floppy?
     
     
     
  2. What happens to files that are currently stored in /floppy when I mount the diskette?
     

  3. When I try to unmount the diskette, I get the message "device busy"; help!
     
     
     

10.  Printing


Notes:


Disclaimer:

·         Printing from floppix works for us, your mileage may vary.

·         Floppix can only print text files.

·         Floppix cannot print on a winprinter.

·         To print to a local printer, it must be a parallel port printer (not serial or USB).

·         To print to a network printer, the server must be accessible using TCP/IP, support lpd and be configured to accept print jobs from your IP.

If printing works in your environment:

·         The command to print a file on a local printer is: lpr <filename>

·         The command to see what jobs are queued for printing is: lpq

·         The command to remove a job from the queue is: lprm <job number>

If a network printer is configured:

·         The command to print a file on a network printer is: lpr -Pnetlp <filename>

·         The command to see what jobs are queued for printing is: lpq -Pnetlp

·         The command to remove a job from the queue is: lprm -Pnetlp <job number>


11.  Finding files


Notes:


The find command searches for files in the filesystem by name, owner, size, date, ... The format of the find command is:
    find [path...] [expression]
where path is the starting point for the search and expression can be a set of options, tests and actions. Some of the tests:

·         -name pattern : search for files whose name matches the given pattern

·         -mtime -n: search for files whose modification time is less than n days (n*24 hours)

·         -user username: search for files owned by the specified user

·         -type x: search for files of type x, where x can be f (file), d (directory), l (link) ...

·         -empty: search for empty files

Examples:

  • find /home -name readme
    This starts the search in the directory /home and looks for a file named readme.
  • find / -user alterego
    This starts the search at the root directory and looks for all files which belong to alterego.
     
  • find / -mtime -1
    This starts the search at the root directory and looks for all files which were modified less than 1 day (24 hours) ago.
     
  • find / -type d -name read
    This starts the search in the root directory and finds all directories named read.  
  • As find scans through the directory tree, there will be directories which you do not have permissions to search. The find command will not scan these directories but will display permission denied messages on standard error. To suppress the permission denied messages, redirect standard error to /dev/null.
     
    find / -mtime -1 2> /dev/null
    This searches for all files that were modified in the last day (24 hours) starting the search in the root directory and sending all 'permission denied' messages to the bit bucket


Exercises:


  1. Find a file named vtree.tgz.
     
  2. Find all files with the filename alterego.
     
  3. Find all files that belong to floopy.
     
  4. Find all empty files in the /etc directory.
     
  5. Find all files under the /etc directory with a filename that starts with K (in uppercase).
     
  6. Find all directories starting in /var.
     
  7. Find a file named penguin.
     
  8. Find all files (not directories) that start with "p".
     
  9. Find all files that end with ".gz".
     
  10. Find everything that belongs to the mail group.


Questions & Answers:


  1. What command will find all filenames ending in .html?
     
     
     
  2. What command will find all files belonging to alterego?
     
     
     
  3. What command will find a directory named netlp starting in the /var directory?
     
     
     
  4. What command will suppress the display of the "permission denied" messages that are displayed when you use the find command?
     
     
     
  5. What command will find all empty directories (use man to lookup options for the find command)?
     
     

12.  Grep


Notes:


The grep command searches the contents of a file for lines that contain a certain pattern.

Examples:

  • grep flin /etc/passwd
    Display the lines from the file /etc/passwd that contain the string flin.
  • grep -v flin /etc/passwd
    Display the lines from the file /etc/passwd that do not contain the string flin.
  • grep -n flin /etc/passwd
    Display line numbers and the lines from the file /etc/passwd that contain the string flin.
  • grep ^f /etc/passwd
    Display the lines from the file /etc/passwd that start with f.
  • grep h$ /etc/passwd
    Display the lines from the file /etc/passwd that end with h.


Exercises:


1.      Use the grep command to display the lines from the file /etc/passwd for users with the flin login shell.
 

2.      Use the grep command to display the lines from the file /etc/hosts.deny that are NOT comment lines (the comment lines are the lines that start with #).
 

3.      Use the grep command to display all lines from any file in /etc/init.d that start with echo.
 

4.      Which files in /etc/init.d contain the string "dmesg"?
 

5.      Which files in /etc/init.d contain the word tr?
Note: use the man command to lookup to option for grep that searches for the word "tr" instead of the string "tr".


Questions & Answers:


1.      What command will display all lines in /etc/init.d/userinitials that start with echo?
 
 
 

2.      What command will display all lines that contain echo in any file in the directory /etc/init.d?
 
 
 

3.      What command will display the lines in the file /etc/login.defs that do not start with # ?
 

4.    What command will display a list of users whose login shell is /bin/bash? (Recall that the login shell is the last entry in the line for each user in the file /etc/passwd).
 
 


13.  Who's on Floppix


Notes:


who:  The who command shows everyone who is currently logged in.

finger:  The finger command displays data about users on the system. To view information about a specific user, enter the command:  finger <username>

last:  On a Linux system, a record of every login session is saved. To view this information, use the last command.

lastb:  The lastb command shows all of the invalid login attempts.

ps:  The ps command shows the processes that are running.


Exercises:


  1. Finger alterego and answer the following questions.
    1. is alterego logged in? 
       
    2. when was the last time alterego logged in?
       
    3. does alterego have mail waiting? 
       
    4. when was the last time alterego read mail? 
       
    5. does alterego have a plan? 
       
  2. What data does finger return about your own account?
     
  3. Use finger to determine if there is a user called superego?
     
  4. Create some data for the last command to display.
    • Login and logout a few times as yourself, alterego and floopy.
    • Make a few mistakes logging in.
       
  1. Enter the command: last
    How many logins were recorded?
     
  2. Enter the command: lastb
    How many login attempts were recorded?
     
  3. Setup the system so alterego and floopy are doing something.
    • Logon as alterego on virtual console 2 and startup vi .
    • Logon as floopy on virtual console 3.
       
  4. On virtual console 1, enter the command: ps aux
    What are alterego and floopy doing?  
     
  5. Is lpd (the line printer daemon) running?


Questions & Answers:


  1. What command will show you who is currently logged in?
     

     
  2. What command will show you all of the failed login attempts?
     

     
  3. What command will show you all of the processes currently running?
     

     
  4. What command will show you the last time alterego read mail?
     


14.  Standard I/O and redirection


Notes:


Definitions:

  • Standard I/O: most unix commands are setup to:
    • get input from standard input (If you are working from a bash prompt, standard input is normally the keyboard)
    • send output to standard output (If you are working from a bash prompt, standard output is normally the screen)
    • send error messages to standard error (If you are working from a bash prompt, standard error is also normally the screen)
  • Redirecting output. When you redirect standard output, the data that would normally appear on the screen is stored in a file instead. Redirect output to a file using > or >>
    • ls -l > flist
      stores the output from ls in flist; if flist already exists, it is overwritten
    • ls -l >> flist
      appends the output from ls to the file flist; if flist does not exist, it is created
  • Redirecting input. When you redirect standard input, any data that would normally be entered from the keyboard is obtained from a file instead. Redirect input from a file using <
    • mail floopy < jokes
      sends floopy the contents of the file jokes instead of waiting for you to type a message on the keyboard
  • Redirecting standard error. Redirect standard error using 2>
    • find / -name jokes 2> /dev/null
      (looks for a file named jokes; sends any "permission denied" messages to /dev/null)


Exercises:


  1. Get a directory listing of /home and save the listing in a file called "one" in your own home directory. Use the cat command to make sure that "one" does contain the correct data.
     
  2. Get a list of everyone currently logged on and save the list in a file called "users "in your own home directory.
     
  3. Get a list of all of the processes that are running and add this list to the end of the "users" file.


Questions and Answers:


  1. What command will suppress the display of the "permission denied" messages that are displayed when you use the find command?

 

 

  1. What command will save a long directory listing of /etc in the file etc.filelist?
     

    15.  Pipes and Filters


Notes:


  1. Pipes. A pipe takes the output from one command and uses it as input to the next command.  Example:
    • ls  -l  /etc  |   more
      display a long listing of the /etc directory and pipe the output through the more command so that it is displayed one screen at a time.
       
  2. Remember:
    • to send the output of a command to a file, use redirection
    • to send the output of a command to another command, use piping
        
  3. Commands that are used in pipelines to modify the output from other commands are being used as filters. All of these commands can be used on their own as well. Commands that are frequently used in pipelines include: grep, sort, wc
     
  4. wc: Count bytes, words and lines
    • wc /etc/passwd
      Count the number of bytes, words and lines in /etc/passwd
    • wc -l /etc/passwd
      Count the number of lines in /etc/passwd
    • wc -w /etc/login.defs
      Count the number of words in /etc/passwd
       
  5. sort: sort lines in a file
    • sort /etc/group
      Sort the contents of /etc/group
    • sort  -r  /etc/group
      Sort the contents of /etc/group in reverse order
    • ls -l | sort -k5n
      Sort the output of ls -l on the size of the files. k5 specifies sort starting on field 5 and n selects a sort in numerical order
       
  6. More examples:
    • What command will count the number of files in the directory var/spool/mail?
       
      Answer:  ls /var/spool/mail | wc -w
       
    • What command will count the number of users whose login shell is /bin/bash? (Recall that the login shell is the last entry in the line for each user in the file /etc/passwd)
       
      Answer:  grep /bin/bash$ /etc/passwd | wc -l
       
    • What command will display a list of everyone who is logged on sorted by their usernames?
       
      Answer:  who | sort 


Exercises:


  1. Copy the file /etc/services to your own home directory. This file contains a list of the port numbers used for Internet network services.
     
  2. How many lines are in the file?
     
  3. Display all of the lines for tcp services.
    Count the number of lines for tcp services.
     
  4. Display all of the lines for udp services.
    Count the number of lines for udp services.
     
  5. Use the "last" command to display the record of all login sessions.
    What command counts the number of login sessions for floopy?
     
  6. Display a long directory listing for the /etc directory.
    Pipe the output of the long directory listing through a grep command that will only display the entries for directories in /etc.


Questions & Answers:


The file called "commands" contains:
cal     /usr/bin    9416
date    /bin        2860
who     /usr/bin    8692
cat     /bin        18056
lpd     /usr/sbin   42012

  1. What is the output of the pipeline:
     
    sort -r  commands  |  head  -1
     

     
  2. What is the output of the pipeline:
    sort  -bk3n  commands  |  head  -1
     

     
  3. What is the output of the pipeline:
    grep  ^c  commands  |  wc  -l
     

      
  4. What is the output of the pipeline:
    grep  usr  commands  |  wc  -l
     

     
  5. What is the output of the pipeline:
    grep  at  commands  |  sort  |  head  -1
     


16.  Passwords and Permisssions


Notes:


Ordinary users have two ways of protecting the data in their accounts:

1. choose a secure password
2. set permissions

Changing your password:

  1. One of the easiest method of breaking into a system is to crack a weak password. To create a secure password:
    • The password should be at least 6 characters long.
    • You should not use names or phrases that are easily obtained; do NOT use your name; do NOT use your dog's name; do NOT use your spouse's name; do NOT use your licence plate; do NOT use your birthdate ...
    • Include both CAPITAL and lowercase letters.
    • Include special characters ( ! @ # $ % ... )
    • Include digits
  2. One way to create a secure password is suggested in the passwd man page.
    • choose 2 small words ( eg: why not )
    • mix in some capitalization ( eg: whY Not )
    • join them with a special character ( eg: whY%Not )
  3. The command to change your password is: passwd

Setting permissions:

Access to files and directories is controlled by a permissions at both the file and directory levels.

  • permissions can be any combination of read, write, execute for the owner, group and world.
     
  • for a file:
    • without read permission, a user cannot view the contents of a file
    • without write permission, a user cannot modify the contents of the file
    • without execute permission, a user cannot execute the file.
       
  • for a directory:
    • without read permission, a user cannot get a directory listing
    • without write permission, a user cannot create new files
    • without execute permission, a user cannot cd to the directory, list the directory contents or save a file in the directory.
       
  • chmod - change permissions.
    • Read, write and execute permissions are set for three groups: the owner, the group and everyone else.
    • chmod 543 myfile would set access rights as follows:
      owner: 5 = 101 binary = read, not write, execute
      group: 4 = 100 binary = read, not write, not execute
      others: 3 = 011 binary = not read, write, execute
       
  • chmod - version 2
    • permissions can also be set using a text representation
      u - user or owner
      g - group
      o - others
      r - read permission
      w - write permission
      x - execute permission
    • chmod u+w file1
      adds write permission for the user
    • chmod +w file1
      adds write permission for the user, group and others
    • chmod go-x file1
      deletes execute permission for the group and others
    • chmod u=r file1
      changes the permissions for the user to be just read permission (group and other permissions are not changed)


Exercises:


  1. Try to change your password to cat. What error message did you get?
     
  2. Try to change your password to blackcat. What error message did you get?
     
  3. Think up a password and change your password.
     
  4. Try to the password for another user. For example, enter the command:  
         passwd floopy
    What error message did you get?
     
  5. Can you view the contents of the directory /sbin?
     
  6. What are the permissions for the directory /sbin?
     
  7. Change the permissions on "readme" in your own home so that you have read/write access, the group has read access and others have no access.
     
  8. Change permissions on your home directory so that you have read/write/execute permissions, the group has read/execute permissions, and everyone else has no access.
     
  9. Make sure that you are in your own home directory. Create a subdirectory called ddd and copy readme to ddd/fff (a file called fff in the ddd subdirectory).
    • what are the permissions on ddd and fff ?
    • change the permissions on fff to only rwx for the owner.
       
  10. Try the following exercise to see some of the operations that you can and cannot do when you have only read permission on a directory.
    • change the permissions on ddd only r for the owner (no permissions for the group and the world)
    • can you get a directory listing for ddd?
    • can you cd to ddd?
    • can you view the contents of fff with the command: cat ddd/fff ?
    • can you delete fff with the command: rm ddd/fff ?
       
  11. Try the following to see what you can do when you have read and execute permission for a directory.
    • change the permissions on ddd only rx for the owner (no permissions for the group and the world)
    • can you get a directory listing for ddd?
    • can you cd to ddd?  
    • can you view the contents of fff with the command: cat ddd/fff ?
    • can you delete fff with the command: rm ddd/fff ?
       
  12. Try the following to see what you can do when you have write and execute permissions for a directory.
    • change the permissions on ddd only wx for the owner (no permissions for the group and the world)
    • can you get a directory listing for ddd?  
    • can you cd to ddd?  
    • can you view the contents of fff with the command: cat ddd/fff ?
    • can you delete fff with the command: rm ddd/fff ?  
    • can you execute the command: cd ; cp readme ddd/fff  ?
       
  13. Try the following to see what you can do when you have only execute permissions for a directory.
    • change the permissions on ddd only x for the owner (no permissions for the group and the world)
    • can you get a directory listing for ddd?
    • can you cd to ddd?
    • can you view the contents of fff with the command: cat ddd/fff ?
    • can you delete with the command: rm ddd/fff ?
    • can you execute the command: cd ; cp readme ddd/fff  ?

 

 

 


Questions and Answers:


  1. The directory entries for the /etc directory and the file /etc/passwd are:
    -rwxr-xr-x 18 root root 1024 May 20 11:58 /etc
    -rw-r--r--  1 root root  658 May 20 11:58 /etc/passwd

Can you modify this file (assuming you are not root)?
 
 

  1. Can you copy /etc/passwd to your own home directory assuming that you have write and execute permissions for your own home directory?
     

     
  2. If you are not floopy, can you copy /etc/passwd (permissions rw-r--r--) to the directory /home/floopy? The permissions on /home/floopy are rwxr-xr-x.
     

     
  3. File1 has permissions: r--r--r--
    You enter the command:
    chmod ug+w file1
    What are the new permissions?
     

     
  4. What command will change the permissions on dir1 so that only the owner has read/execute access?
     

     
  5. Can you cd to dir1 given the permissions are drw-------?
     

  6.  What command will change the permissions on dir1 so that you have write/execute permissions only?
     

  7.  Can you copy readme (permissions r--r--r--) to dir1 (permissions d-wx------ ) if you own dir1?

 

  1. Can you get a directory listing for dir1 permissions (d-wx-wx-wx)?

 


 
 17.  Umask: Setting default permissions


Notes:


Every new file or directory that you create will have some set of default permissions assigned to it. You can set what these permissions will be with the umask command.

Notes on umask:

  1. The umask command can be used to set default permissions for any new file that is created; it will not reset the permissions for existing files.
     
  2. On the linux filesystem, files cannot be set executable by default.
     
  3. Umask determines which permissions are NOT allowed; it is the opposite of chmod. The command: umask 026 gives:

permissions for the user are 0 = 000 binary

read allowed, write allowed, execute allowed

permissions for the group are 2 = 010 binary

read allowed, write NOT allowed, execute allowed

permissions for others are 6 = 110 binary

read NOT allowed, write NOT allowed, execute allowed
 

  1. If the umask is 026, a new directory will have permissions: rwxr-x--x
     
  2. If the umask is 026, a new file will have permissions: rw-r-----
    (the execute permissions are not turned on automatically)


Exercise:


  1. What is your current umask value? (enter the command: umask)
     
  2. Use the mkdir command to make a new directory. What are the permissions for this directory?
     
  3. Use the touch command to create a new file. What are the permissions for this file?
     
  4. Set the umask to 022.
     
  5. Use the mkdir command to make a new directory. What are the permissions for this directory?
     
  6. Use the touch command to create a new file. What are the permissions for this file?
     
  7. Change your umask so that the default permissions for any directory that you create are rwx------. What is the umask?
     
  8. Create a new directory. Verify that the umask worked.
     
  9. With this umask, what are the permissions for a new file?


Questions & Answers:


  1. What command will change the permissions on the existing file readme to rw-rw-r--?
     
     
     
  2. Assume that the "new" directory does not exist. The following commands are executed:
         umask 027 ; mkdir new
    What are the permissions for the new directory?
     
     

 

  1.  Assume that "newfile" does not exist. The following commands are executed:
         umask 027  ;  touch newfile
    What are the permissions for the new file?
     
     

18.  The search path


Notes:


  1. When you enter a command, the operating system has to search for that program. The path defines the directories which the system will search.
     
  2. To find out your current path, enter the command: echo $PATH
    The output may be: /usr/bin:/bin
    The path is a list of directories separated by colons.

    The path /usr/bin:/bin means that when you enter a command, the shell will search for the program in the directory /usr/bin and then in the directory /bin. If the program is stored in either of these 2 directories, it will run; if the program is not stored in either of these 2 directories, you will only get an error message.
     
  3. To change the path to /bin, use the command: PATH=/bin
    To add the directory /usr/local/bin to the existing path, use the command: PATH=$PATH:/usr/local/bin
     
  4. Note: the current directory is NOT automatically included in the search path. If there is an executable program called greatgame in the current directory, entering the command, "greatgame" results in the error message "command not found". You can see the file, but the shell cannot. To run the program, enter the command "./greatgame".
  5. Without a path, you would have to know where every program is stored on your system. To use the cal program, you would have to type /usr/bin/cal ; to use the date program, you would have to type /bin/date ; etc


Exercises:


  1. What is your current search path?  
     
  2. Change the path to include /usr/bin , /bin , /usr/sbin .
     
  3. Verify that the search path was changed by entering the command: echo $PATH
     
  4. Change your path so that it includes ONLY your home directory.
     
  5. Verify that the search path was changed.
     
  6. Try to get a directory listing - what happens?
     
  7. Now try to get a directory listing using the command: /bin/ls. Did this work?
     
  8. Logout and login again. What is your search path now?

19.  Configuring your account


Notes:


The passwd file:

  1. On a unix system, the user database file is /etc/passwd. This file keeps a list of all of the accounts on the system with some configuration data for each account.
     
  2. Each user has a one line entry in the passwd file; each line contains 7 fields separated by colons as follows:  
    username:password hash:uid:gid:gecos:home directory:login shell.
    The gecos data is your name,office,home phone,work phone,other
     
  3. A sample line from the passwd file is:
        abc:*:1004:100:Mr. Alphabet:/home/abc:/usr/bin/flin
    username:  abc
    password:  *
    userid:  1004
    groupid:  100
    name:  Mr. Alphabet
    home directory:  /home/abc
    login shell:  /usr/bin/flin

Other commands to view or change data about your account.

  1. id
    shows your userid, groupid and all groups you belong to.
     
  2. set
    displays the name and value of each shell variable; this includes your terminal type, your search path, your mail directory, ...
     
  3. chfn
    This command is used to change your personal information in the passwd file.
     
  4. chsh
    This command is used to change your login shell.
     


Exercises:


  1. Look at the entry in the passwd file for your account. What is your uid?
     
  2. Look at the entry in the passwd file for floopy. What is the shell?
     
  3. What is your uid; what is your current gid; what groups are you a member of?
     
  4. What is the name of the file that is checked for incoming mail? (MAIL) What is your terminal type?  (TERM) What is your path? (PATH)
     
  5. Use the chfn command to enter home and office phone numbers for your account. Look at your entry in the /etc/passwd file. Are the phone numbers stored there? Use the finger command to finger your own account. Are the phone numbers displayed?
     
  6. Change your login shell to /usr/bin/flin. Logout and login again. You should be running flin (a menu based shell). Check your entry in the passwd file. Was the login shell changed.

20.  Configuring the bash shell


Notes:


Bash Configuration files:

  1. You can setup files that automatically configure your working environment every time you login. The three major configuration files for the bash shell are:
    1. /etc/profile - generic system-wide profile
    2. .bash_profile - personal profile that is processed every time you login
    3. .bashrc - setup file processed every time you open a non-login shell

Modifying the prompt:

  1. In a command interface, the prompt is what you see on the screen when the system is waiting for you to enter your next command.
  2. Under the bash shell, the primary prompt is stored in a variable called PS1.
  3. To change the prompt you use the command: PS1='value'
    eg:  PS1='type something!  '
  4. Some of the codes that can go in the prompt are:
    • \d the date (day-of-the-week month day)
    • \h the hostname (without the domain)
    • \n start a new line
    • \u the current username
    • \w the working directory

Aliases.

  1. An alias lets you setup typing shortcuts. An example of an alias would be:
     alias byebye='logout'
    When you type byebye, bash will interpret this as logout.
  2. To cancel the alias, use the command:
    unalias byebye
  3. To view any aliases that are already defined for your account, use the command: alias

Bash Shell Options:

  1. There are a number of options that can be set; one of the most useful is the noclobber option. If noclobber is on, then you cannot accidentally overwrite a file using redirection.
  2. The command to turn on the noclobber option is: set -o noclobber
  3. The command to turn off the noclobber option is:


Exercises:


  1. Answer the following questions about the current setup:
    1. What is stored in the current .bash_profile?
    2. What is your prompt?
    3. What is your path?
    4. What is your umask value?
    5. Are there any aliases set up?
       
  2. Change the prompt as follows:
    1. Change the prompt to -->
    2. Change the prompt to 2 lines:
         Get going
         Enter your next command>
    3. Change the prompt to: your working directory followed by a $
    4. When you change directories, does the prompt change to the new directory name? (it will if you've set it correctly)
    5. Logout and login again. Was the new prompt saved or has it gone back to $ ?
       
  3. Setup aliases as follows:
    1. Setup dir as an alias for ls -l . Type dir. Did you get a long directory listing? __
    2. Is "rename" a valid command in floppix? _____
      Make rename an alias for mv. Now you should be able to use the command:
      rename readme ignoreme
      This should change the name of the readme file. Did it work?
    3. Does the rm command ask for confirmation before a file is deleted? Test it out.
      • copy the passwd file to mypass: cp /etc/passwd mypass
      • remove the passwd file: rm mypass
      • did you receive a confirmation request before mypass was deleted? ___
    4. Create the following alias: rm='rm -i'
    5. Test your alias:
      • copy the passwd file to mypass: cp /etc/passwd mypass
      • remove the passwd file: rm mypass
      • did you receive a confirmation request before mypass was deleted?
         
  4. Test the noclobber option
    1. Turn on the noclobber option.
    2. Create the file flist using the command: ls -l > flist
    3. Repeat: ls -l > flist
    4. Did you get an error message?
    5. Turn off the noclobber option.
    6. Enter the command:  ls -l /etc > flist
    7. This time the command should overwrite flist with a newer version. Did it?
    8. Point to remember:
      -o turns noclobber ON
      +o turns noclobber OFF
       
  5. Create a .bash_profile that:

1.      sets the background color of the screen to black.

2.      sets the prompt to the name of the working directory followed by $ .

3.      sets the search path to /usr/bin and /bin .

4.      sets dir as an alias for ls -l .

5.      configures rm to prompt for confirmation before deleting a file.

6.      prevents bash from overwriting an existing file when redirecting output

7.      Test your profile - logout and login again.


21.  Managing processes


Notes:


Because unix is a multi-tasking operating system, each user can have many commands running at one time. Using the bash shell, users can run programs in the foreground (interacting with the terminal) or in the background (running but not interacting with the terminal). If a job is running in the background, the user can continue to work on other tasks at the command prompt.

New commands:

  1. ps - displays a list of your processes. Options:
    • a - display processes of all users
    • u - give user name and start time
    • x - show processes that are not associated with a terminal
  2. If a process is running in the foreground, [crtl-z] suspends it.
  3. To start a process in the background, end the command line with &
    eg:  cp * /tmp &
  4. bg - backgrounds a process (suspend it first)
  5. jobs - lists background processes
  6. fg - foregrounds a process (if there is more than one background task, fg %2 will foreground job 2)
  7. kill - terminates a process.
    Note: sometimes killing a process can have unexpected side effects. Killing the process can leave behind temporary or locked files.
  8. sleep - pauses a specified number of seconds


Exercises:


  1. Use the ps command:
    1. Enter the command ps au
    2. What processes are running on tty1?
    3. What processes are running on tty2?
    4. Switch to virtual console 2, login as alterego and enter the command ps au again.
    5. What processes are running on tty1?
    6. What processes are running on tty2?
    7. Logout on virtual console 2; switch back to virtual console 1.
    8. What processes are running on tty1?
    9. What processes are running on tty2?
    10. Enter the command: ps aux
    11. What additional processes are running?
       
  2. Suspend, background, foreground, kill
    1. Start links.
    2. Suspend it.
    3. Enter the command: (sleep 60 ; sleep 60 ; ls -l > flist)
      (make sure that you include the brackets; this command means: wait 60 seconds, wait 60 seconds, save the output from ls -l in the file flist).
    4. Suspend this command.
    5. Back |ground the sleep process started in step 3.
    6. Foreground links
    7. Suspend links
    8. Kill links
    9. Check to see if the sleep command line has finished


Questions and Answers:


  1. What command lists all of your processes?
     
     
  2. What command lists all running processes?
     

     
  3. If the status of one of your processes is [Suspended], how do you restart it?
     

     
  4. How would you run ( sleep 60 ; ls -l > listing ) as a background job?
     

     
  5. How do you background a running process?
     
     
  6. If a process is running in the background, how do you move it to the foreground?
     

7. How do you terminate a process, pid 345 and job number 4?
 

8.  If job 4 does not respond to the normal kill command command, what command will kill it?
 

 

22.  Sending and receiving e-mail


Notes:


Sending e-mail to another user on floppix:

  1. Type: mail <username>
  2. At the "Subject:" prompt, type in a subject and press [Enter]
  3. Type in the message line by line
  4. To send the message, press [Ctrl-d] at the beginning of a new line
  5. A sample session sending mail could look like:
     
    $ mail alterego
    Subject: studying
    Linux is fun
    Remember our 2:00 meeting to do the mail lab
    ^D

Reading email

  1. To read the email, login as alterego and type: mail
  2. The mail program will show a list of messages:
    ----------------------------------------------------------
    Mail version 8.1 6/6/93. Type ? for help.
    "/var/spool/mail/alterego": 2 messages 2 new
    >N 1 student Sun Sep 20 13:00 14/395 "lab1"
     N 2 student Sun Sep 20 13:01 14/409 "lab1 answers"
    &
    ----------------------------------------------------------
  3. Some mail commands:
    • To read message 2, type 2.
    • To delete message 2, type d2.
    • To reply to message 2, type r2.
    • To get help, type help or ?
    • To exit, type q
  4. When you exit from mail with the q command, the messages that you have read (and not deleted) will be saved in a file called mbox. Unread messages will go back to the mail spool file.
  5. To view the mbox file from the mail utility, open mail with the command: mail -f
  6. Mail messages that you have not picked up yet are saved in a spool file. On floppix, the mail spool file is called /var/spool/mail/username .

Sending/receiving e-mail - real mode

  1. If you are connected to the Internet and you configured e-mail during the startup, you can send and receive real e-mail.
  2. Use mail to compose messages. If the message is addressed to a user on another system it will be forwarded to your SMTP server.
  3. Run fetchmail to download your mail from your POP3 server.
    The mail will be downloaded to your local spool file; use mail to read it. A copy of your mail will be left on the server so that you can also download the messages with your normal email package.
  4. The configuration file for fetchmail is .fetchmailrc which is stored in your own home directory.


Exercises:


  1. Send an email message to alterego.
     
  2. Switch to another virtual console, login as alterego and read the mail messages. Send a response.
     
  3. Switch to the first virtual console (where you are logged in as yourself) and read the response from alterego. Quit the mail program.
     
  4. Check that you have now have a file called mbox in your home directory.
     
  5. What command to you use to re-read the message from alterego?

23.  Telnet


Notes:


  1. Telnet is a terminal emulation protocol. It allows you to connect to a server using your PC as a terminal. Once you start a telnet session, all of your work is done on the remote system - all commands are executed on the remote system and all files are created and deleted on the remote system.
     
  2. Start a telnet session with the command:  telnet <hostname>
    If the remote system accepts the request for a telnet session, you will get a login prompt.
    To terminate the telnet session, logout.


Exercises:


  1. If you are not connected to the Internet, you can still run a practice telnet session by running a telnet session to your own PC (rather mind-bending - your own PC is acting as both the local and the remote servers). Try the following:
    • telnet localhost
       
    • login as alterego
       
    • enter the command: who am i
       
    • you should see output similar to the following line:
        floppixabc!alterego ttyp0 MMM dd, hh:mm (localhost)
      This means: you are logged in on the server floppixabc, your userid is alterego, you are using virtual console ttyp0, the date is MMM dd, hh:mm and you are logged in from localhost (this will be the name or the IP of the system you are connected from)
       
    • when you logout, the telnet connection is terminated
       
    • telnet localhost again. The server will respond will several messages:
      Connected to localhost
      Escape character is '^]'
      Pay attention to the escape character; it can differ from server to server; if you want to abort a job on the remote system, use the escape character.
       
  2. If you are connected to the Internet under Floppix, you can telnet from Floppix to any server where you have a login account and telnet access.

24.  Ftp


Notes:


  1. Ftp - file transfer protocol - is used to transfer files between systems.
     
  2. Some ftp commands:
    • dir - lists the contents of the remote directory
    • cd - changes directories on the remote server
    • ascii - sets the mode for transferring text files; text data is translated if required
    • binary - sets the mode for transferring non-text files without any tranlation.
    • get filename - downloads the file from the remote server
    • put filename - uploads the file to the remote server
    • lcd - changes directories on the local system
       
  3. Many sites on the Internet allow you to download software using anonymous ftp. When you connect to an anonymous ftp server, enter "anonymous" for the username and your complete email address for the password.


Exercises:


  1. If you are working stand-alone, try the following:
    • ftp localhost
    • login as floopy
    • download penguin
    • quit
       
  2. If you are connected to the Internet, use anonymous ftp to download the gnu public license from metalab.unc.edu. This file is in the /pub/Linux/LICENSES directory.

25.  A text web browser


Notes:


  1. The current version of floppix includes a text based web browser called links.
  2. Launch the browser with the command: links
  3. This is a text browser, so you will not see images.
  4. Some keystroke commands:
    • To scroll through a document use pgup, pgdn, up-arrow and down-arrow.
    • To follow a link, use the right arrow;
    • To go back, use the left arrow
    • To go to a specific URL, type g and then enter the address.
    • To see the command menu, press [esc]
    • To exit from links, use [ctrl-c]

26.  Very Simple Bash Scripts


Notes:


1.      A bash script is a file containing a list of commands to be executed by the bash shell.
 

2.      The very simplest scripts contain a set of commands that you would normally enter from the keyboard. For example: the following lines are stored in the scripts colorme.
 
#! /bin/bash
# script to turn the screen blue
setterm -background blue
echo It is a blue day
 
Line 1: specifies which shell should be used to interpret the commands in the script.
Line 2: is a comment (has no effect when the script is executed).
Line 3: sets the background colour.
Line 4: displays a message.
 

3.      To run the script:

o        Method 1:

      • Make the script executable: chmod 700 colorme
      • Try to run the script by typing the command:  colorme
      • You will get the error message: command not found
      • Remember, a unix system will only only look for commands or scripts in the directories in your search path. So the system looks for the "colorme" command in the directories /usr/bin and /bin, doesn't find it and returns the error message.
      • Run the script with the command:
        ./colorme
        which means: run colorme from the current directory
         
    • Method 2:
      • If you are getting error messages when you run the script, you can trace the lines as they execute using the command: bash -v colorme
      • As the script executes, each line is displayed on the screen so that you know exactly what your script is doing.
         
  1. Using variables in a script
     
    Variables are created when you assign a value to them ( eg: COLOR=blue )
    To use the variable, put a $ before the variable name. ( eg: echo $COLOR )
    Modify the colorme script to use the color variable as follows:

    #! /bin/bash
    COLOR=blue
    setterm -background $COLOR
    echo It is a $COLOR day
     
  2. Getting user input
     
    A script can get input from the user while it is running. Use the echo command to display a prompt on the screen and the read command to get the input.
      
    #! /bin/bash
    echo -n "Pick a screen color (blue, yellow, red ): "
    read -e COLOR
    setterm -background $COLOR
    echo It is a $COLOR day
     
  3. Passing Parameters on the command line:
     
    You can also pass parameters to the script on the command line. Bash will accept up to 9 parameters separated by spaces. The first parameter is $1, the second parameter is $2, etc. The colorme script using input parameters is shown below.
     
    #! /bin/bash
    setterm -background $1
    echo It is a $1 day
     
    To run the script, use the command: colorme red
    In this case, $1 will be given the value "red".
    Run the script again using the command: colorme blue
    This time, $1 will have the value "blue".


Exercises:


  1. Write a script called checking that displays information about a specified user.
    The script should:
    • display a prompt asking for the username
    • read the user input
    • finger the user
    • display any results from the who command about this user only
    • display any results from the ps command about this user only

Test your script using your own username. Then, login on another console as floopy, switch back to your own console and make sure that your script displays the correct data about floopy.
 

  1. Code a script called dirchk that displays data about the current directory. The script should:
    • display a count of the number of subdirectories of this directory.
    • display a count of the number of files in the directory.
    • list all of the files in the directory that are zero length (use an option of the find command to do this)
    • use du to display the amount of storage space used by this directory

To test your script, you should create some subdirectories, some files that are zero length using touch and some files that are not zero length using vi, redirection or cp.


27.  Superuser


Notes:


  1. On a unix system, ordinary users will get the message "Permission Denied" if they try to perform tasks such as adding/deleting other users, adding/deleting programs in /usr/bin or backing up all files in the directory /var/spool/mail . Tasks such as these are system administration/maintenance tasks. To perform the tasks that can only be done without the restrictions that apply to normal user accounts, the administrator must use the superuser account.
     
  2. The superuser account has the uid 0 and normally uses the username root . This account is not restricted by any of the permissions or constraints that apply to a normal user account. This allows the superuser account to perform the required system maintenance activities. But the lack of restrictions also means that the superuser account has none of the usual safeguards and must be used with care; unix legends are full of stories of administrators logged in as root who typed " rm -rf / " and deleted the entire filesystem.
     
  3. There are 2 ways that you can become root:
    1. login as root (on Floppix all passwords are the same so the root password is the same as your normal user password).
    2. login using your normal user account and then enter the command: su -
      The su command (substitute user) allows you to take on another user identity; if su is entered without specifying a username, it allows you to become superuser (assuming that you have the superuser password).
       
  4. Method 2 is preferable for 2 reasons:
    1. If you are already logged in, you are more likely to exit from the superuser account back to your own account when you are finished the administration activities. When you are using your own account, a mistake will not bring the entire system down.
    2. If you su to the superuser account, a log entry shows the time, date and username of the person who su'd to root.


Exercises:


  1. Login using your own account.
     
  2. Try to delete the file /etc/passwd. What message do you get?
     
  3. Use the su command to become root.
     
  4. Check the log and find the entry for the su command. ( on Floppix, the system logs are directed to /dev/tty8 ; press [alt][F8] to see the logs; [alt][F1] to return to console 1)
     
  5. What is the output from each of the following commands?
    • who
    • who am i
    • whoami
       
  6. IF YOU ARE NOT WORKING ON FLOPPIX STOP HERE- DO NOT CONTINUE.
     
  7. If you are working on floppix, delete the file /etc/passwd .
     
  8. Logout.
  9. Now:
    • Can anyone login?
    • Can you use [alt][ctrl][del] to reboot?
    • How do you recover?
      You can't! You will have to use the reset or power switch to restart your system. On Floppix, this is annoying but it will give you access to your system again.
      If you were working on a real system, you have just locked everyone (including yourself) out. To recover, you must load linux using a rescue diskette and then restore your password file from system backups (as a good system administrator, of course you have backup tapes.)
    • Remember, when you are working as root, you have no safeguards. Check every command twice before you press [enter] . And if you are not sure what a command will do, the root account is not the place to experiment.

28.  Adding New Users


Notes:


  1. Adding new users can only be done by a user with superuser privileges.
     
  2. Normally adding new users is handled by means of a script or utility (called useradd, or adduser ...) Users can be added manually but on a production system, you should use the utility programs since they will handle tasks such as locking the passwd file while it is modified.

    It is a valuable exercise to go through the process of adding users manually on a practice system; this provides a solid understanding of the files that control each aspect of a user account giving you the knowledge required to prevent or troubleshoot any problems.

On Floppix (of course), users must be added manually.
 

  1. When new users are added, you must modify the file /etc/passwd and possibly /etc/group. Be careful when you modify these files; a mistake could mean either that no-one can access your system or that everyone has root access to your system.
     
  2. In Debian, each new user is added with their own group; for example, if samiam is added as a user and a group called samiam would be setup with samiam as the only member.
     
  3. User id's are allocated as follows:
    • uid 0 - reserved for the superuser
    • uid 1-99 - reserved for administrative accounts
    • Debian starts assigning new userids at 1000


Exercises:


Add a new user called samiam following these steps

  1. Edit /etc/passwd and add an entry for the samiam user. Put this line at the end of the file.
    samiam:*:1003:1003:DrSuess:/home/samiam:/bin/bash
    Interpretation:
    • samiam : the username
    • * : the password (you cannot login using this password; the * prevents anyone from logging as samiam until the account is completely setup)
    • 1003 : the userid
    • 1003 : the groupid (this does not have to be the same as the uid)
    • Dr. Suess : the real name
    • /home/samiam : the home directory
    • /bin/bash : the login shell
       
  2. Edit /etc/group and add an entry for the samiam group at the end of the file. The line should be:
    samiam:*:1003:
    Interpretation:
    • samiam : the groupname
    • * : the group password (for security reasons, group passwords should not be assigned)
    • 1003 : the groupid
    • the fourth field is left empty. For multiuser groups, this field would be a list of the users in the group separated by commas.
       
  3. Create a home directory for samiam; this directory should be /home/samiam.
     
  4. Copy the system configuration files from /etc/skel to the home directory. Note: there are files in /etc/skel .
     
  5. Change the ownership so that the home directory and all of its contents are owned by samiam. The commands are:
    chown -R samiam /home/samiam
    chgrp -R samiam /home/samiam
    The -R parameter changes the owner (or group) of the directory and everything stored in that directory.
     
  6. Check the permissions on the /home/samiam and its contents. Samiam must have rwx permissions on his home directory; the world should not have any permissions.
     
  7. Change the password. ( passwd samiam )
     
  8. If you want to fill in the rest of the gecos data ( chfn samiam )
     
  9. Now that you have created the account, switch to console 2 and make sure that you can login as samiam.
     
  10. If you cannot login as samiam, check the entries in /etc/passwd and /etc/group. Once you can login, you should also check that:
    • you are in the directory /home/samiam
    • the .bash_profile executed properly (the screen should be blue)
    • you can create a newfile in this directory (there is not much point in giving a user a home directory if they cannot store files in it)

Question and Answer:  Experiment with the samiam account

  1. Edit /etc/passwd and put a * at the beginning of the password field for samiam. Switch to another console and try to login as samiam. What happens?

     
  2. Edit /etc/passwd and delete the * you inserted. Switch to another console and try to login as samiam. What happens?

     
  3. Edit /etc/passwd, delete the password field for samiam and then login as samiam. What happens?

     
  4. Edit /etc/passwd, change the home directory for samiam to /tmp and then login as samiam. What happens?

     
  5. Edit /etc/passwd, change the login shell for samiam to /usr/bin/flin and then login as samiam. What happens?

     
  6. Edit /etc/passwd, change the login shell for samiam to /usr/bin/passwd and then login as samiam. What happens?

     
  7. Edit /etc/passwd, change the login shell for samiam to /bin/true and then login as samiam. What happens?

     
  8. What will happen if you change samiam's login shell to /bin/ls? Test your answer to see if you are correct.
     
  9. Edit /etc/passwd, change the login shell for samiam to /bin/bash, change the gid for samiam to 100 and then login as samiam. Use touch to create a new file. What group does the file belong in?

     
  10. Edit /etc/passwd, change the uid for samiam to 0 and then login as samiam. How can you test to see if samiam has superuser privileges? Is samiam now a superuser account?

Setup an account for iamsam that is ftp only (iamsam can ftp but cannot login)

  1. To get ftp access, the iamsam account must satisfy 3 conditions:
    • iamsam must have an entry in /etc/passwd with a non-null password
    • iamsam cannot be listed in the file /etc/ftpaccess (this file lists all of the users who do NOT have ftp access)
    • iamsam must have a valid login shell as listed in /etc/shells
       
  2. Starting with the shell, make iamsam's login shell /bin/true. Edit /etc/shells to include /bin/true as a valid login shell.
     
  3. Make sure that iamsam is not listed in /etc/ftpaccess.
     
  4. Create an account for iamsam following the steps used to create the samiam account. Make sure that you use a unique username, uid, groupname, gid, and home directory. Make sure that the login shell is /bin/true so that iamsam will not have shell access.

29.  Working with groups


Notes:


1.      Users can belong to one or more groups.

2.      Each group may be given different access permissions for working directories and programs.

3.      Ordinary users can determine which groups they belong to with the id command; and can change groups with the newgrp command.

4.      Only the superuser can add members to a group.


Exercises:


1.      As superuser, create a group called readers. The password should be * , the gid should be 200 and initially, there should not be any users in this group.
 

2.      Create the subdirectory /home/readers. This subdirectory should be owned by the user root and the group readers. The permissions on this subdirectory should be rwxr-x---. Copy /etc/passwd to /home/readers.
 

3.      On another virtual console, login as alterego. Can you:
- list the contents of /home/readers? (answer should be no)
- cd to /home/readers? (answer should be no)
- cat /home/readers/passwd? (answer should be no)
- create a file in the directory /home/readers? (answer should be no)
Logout.
 

4.      As superuser, add alterego and floopy to the readers group. The line in /etc/group should now be: readers:*:200:alterego,floopy
 

5.      On another virtual console, login as alterego.
Use the "id" command to verify that you are now a member of the readers group.
What is your gid? _____
Can you:
- list the contents of /home/readers? (answer should now be yes)
- cd to /home/readers? (answer should now be yes)
- cat /home/readers/passwd? (answer should now be yes)
- create a file in the directory /home/readers? (answer should still be no)
 

6.      Still working as alterego
- cd to your own home directory
- what is your gid? (use the "id" command to determine this) _____
- use touch to create a new file called test1
- which user and group own test1?
- enter the command: newgrp readers
- what is your gid? (use the "id" command to determine this) _____
- use touch to create a new file called test2
- which user and group own test2?
- logout
 

7.      As superuser, change the permissions on /home/readers to rwxrwx---.
 

8.      Login as alterego.
- what is your gid? (use the "id" command to determine this) _____
- cd to /home/readers
- use touch to create a new file called test3.
- Who owns test3? Which group owns test3?
 

9.      As superuser, change the permissions on /home/readers to rwxrws---.
 

10.  Login as alterego.
- what is your gid? (use the "id" command to determine this) _____
- cd to /home/readers
- use touch to create a new file called test4.
- Who owns test4? Which group owns test4?


30.  Runlevels


Notes:


  1. Runlevels allow the system administrator to automate different system configurations. On a laptop, for example, you may have one runlevel setup to configure the system when it is in a docking station and a different runlevel setup to configure the system when it is mobile. On floppix, 4 runlevels are setup:
    • runlevel 0 is for system shutdown
    • runlevel 1 is single user (used when the system administrator needs to perform system maintenance that cannot be done when other users are logged on)
    • runlevel 2 is the normal multi-user configuration (note that other Linux distributions define runlevels 2-5 differently; check the documentation for your own distribution)
    • runlevel 6 is for rebooting
       
  2. The command to determine the current runlevel is: runlevel
    The output will be 2 characters - the previous runlevel (N if there was no previous runlevel) and the current runlevel.
     
  3. The command to change runlevels is: telinit x
    where x is the new runlevel.


Exercises:


  1. Determine the current runlevel.
  2. Change to runlevel 1.
  3. Shutdown floppix by changing to runlevel 0.
  4. Restart floppix in single user mode ( loadlin linux single )
  5. Now change to multi-user mode which is runlevel 2.


Questions & Answers:


  1. What runlevel is configured for halting the system?
     
     
  2. What is single-user mode?
     

     
  3. What command is used to change to runlevel 1?
     

     
  4. Can you choose a runlevel when you start the system?
     

 
 
 


31.  Hardware Detection: System startup - step I


Notes:


1.      The first step in booting a linux system is loading the kernel. This can be done in a variety of ways:

    1. Loadlin - loadlin runs from DOS, removes DOS from memory and loads linux kernel.
    2. Lilo (linux loader) - lilo replaces the MBR on the hard drive with code that will locate and load the linux kernel. Lilo can be configured to boot other operating systems as well as linux.
    3. Raw copy the kernel image to a floppy diskette (using the dd command). This diskette will not have a filesystem on it and you will not be able to get a directory listing for it but you will be able to boot from it.
       
  1. Once the kernel is loaded, it performs a set hardware detection routines which search for and identify devices in your system. The messages that appear on the screen during system startup show the results of this phase. You can also view these messages at anu time using the "dmesg" command. If you cannot get something to work (eg: networking, printing, dialup), first check is the boot messages to see if the device is supported.
     
  2. The linux kernel can be customized for a wide range of microcomputer systems and peripheral devices. The version of the kernel that floppix uses has been compiled with no support for hard drives, cd drives, sound cards, modems, mice, scanners, tape backup drives, ... This does NOT mean that this support is not available; it only means that it is not available in the version of the kernel floppix uses.


Exercises:


Run dmesg and answer the following questions (if the data scrolls off the screen, pipe the output through the more command to view it one screen at a time)

speed:

1.      how fast is your system (in bogomips)? _________

memory:

1.      how much total memory is installed? __________

2.      how much memory is in use by the kernel? __________

3.      how much memory is available for processes, data, ... __________

printing:

1.      did the kernel detect a parallel port (lp_)? __________

2.      which port is it (lp0, lp1 or lp2)? __________

3.      what I/O address is the port using? __________

nic:

1.      did the kernel detect a network card (eth0)? __________

2.      what type of network card (tulip, smc, 3com, ... ) __________

3.      what I/O address is the network card using? __________

disk drives:

1.      did the kernel detect a floppy drive (fd_)? __________

2.      what did it identify about the drive? __________

3.      did the kernel detect an ide hard drive (hd_)? __________

4.      did the kernel detect a scsi hard drive (sd_)? __________

5.      did the kernel detect a cdrom drive?__________


32.  init and inittab: System startup - step II


Notes:


  1. Init is the first process started once the kernel is loaded. Init handles starting all daemons and processes, restarting processes like getty which allow users to login, collecting orphan processes and shutting the system down. Since init is the parent process for all other process, configuring the tasks that are performed when the system starts up or shuts down is done by configuring init.
     
  2. The configuration file for init is /etc/inittab. Each line in the inittab file consists of:
    • a one to four character identifier (this can be any identifier except for the getty entries where the identifier should be 1 for the getty on tty1, 2 for the getty on tty2, etc)
    • the runlevels where the entry is active
    • the type of action (possible actions include initdefault, sysinit, ctrlaltdel, wait, respawn ...)
    • the command to execute
       
  3. A sample inittab file with comments is shown below:

# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.8 1998/05/10 10:37:50 miquels Exp $

# The default runlevel.
id:2:initdefault:

# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# of runlevel. #
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.

l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

# /sbin/getty invocations for the runlevels. #
# The "id" field MUST be the same as the last
# characters of the device (after "tty"). #
# Format: # <id>:<runlevels>:<action>:<process>
1:2345:respawn:/sbin/getty 38400 tty1
2:2345:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3


Exercises:


  1. Make sure that console 4 is NOT active by trying to switch to this console.
    Modify inittab to start a fourth virtual console.
    Have init reread the configuration file.
    Verify that console 4 is active.
     
  2. Currently init is configured to reboot when ctrl-alt-del is pressed. Modify inittab so that the system changes to runlevel 1 when ctrl-alt-del is pressed. Make sure that you have init reread the configuration file. Press ctrl-alt-del to test your work.

33.  rc.d Directories: System startup - step III


Notes:


1.      Inittab is the first configuration file for init, but that is not the end of the story. There are also a whole set of scripts that run on system startup or shutdown that control exactly which daemons are stopped or started and any other tasks that need to be done.
 

2.      In a Debian Linux system, all scripts that are run at startup or on a change of runlevel are stored in the directory /etc/init.d
 

3.      The directory /etc/rcS.d controls which of the scripts from /etc/init.d are run at startup.
The directory /etc/rc0.d controls which of the scripts are run on a change to runlevel 0.
The directory /etc/rc1.d controls which of the scripts are run on a change to runlevel 1.
The directory /etc/rc2.d controls which of the scripts are run on a change to runlevel 2.
etc.
 

4.      Each of the "rc" directories contains symbolic links to the required scripts in /etc/init.d. The links are either "S" links which start a service or "K" links which kill a service. Each of the linknames must start with an uppercase S or K followed by a 2 digit sequence number. The K links will be executed first in order followed by the S links.
 

5.      For example: in floppix, /etc/rc6.d contains these links:

    • K11cron - stop cron
    • K13dhcpc - stop dhcpcd (the daemon that requests server assigned ip addresses)
    • K18netbase - stop inetd
    • K20iplogger - stop the icmp and tcp logging daemons
    • K25lpd - stop the lpd printer daemon
    • K90sysklogd - stop system & kernel logging
    • S20sendsigs - kill any remaining processes
    • S40umountfs - unmount the filesystems
    • S90reboot - reboot
       
  1. You can change the tasks that are performed for each runlevel by either
    • deleting a link in the appropriate rc directory
    • or coding a new script, storing the new script in /etc/init.d and then adding a link to the new script in the appropriate rc directory

 


Exercises:


  1. Answer the following questions about the current setup:
    1. What is the default runlevel for floppix?  _____
    2. What directory contains the S and K links for this runlevel? _____
    3. What K links (if any) exist for this runlevel? _________________________
    4. What S links (if any) exist for this runlevel? _________________________
    5. What command will show you if the following services are running: syslogd, klogd, icmplogd, tcplogd (they should be but check and make sure that they are)
       
  2. Configure rc2.d so that syslogd, klogd, icmplogd and tplogd do not startup in runlevel
    1. Change to the directory /etc/rc2.d
    2. Delete the link that starts up syslogd and klogd. (you will have to look at the contents of the individual scripts to see which link to delete)
    3. Delete the link that starts up icmplogd and tcplogd.
    4. Switch to runlevel 1 and then back to runlevel 2.
    5. Verify that syslogd, klogd, icmplogd and tcplogd are not running.
       
  3. Add a new script that runs everytime you switch to runlevel 1.
    1. Change to the directory /etc/init.d
    2. Code a script called red that:
      • turns the screen red
      • displays the message "Entering runlevel 1"
      • displays a list of all of the processes that are currently running
    3. Make sure that your script will run.
    4. This script should run every time you change to runlevel 1. So change to the directory /etc/rc1.d
    5. Put an K link to your script in the directory rc1.d so that the script will be the first script to run when the system shuts down as follows:
      ln -s /etc/init.d/red K01red
    6. Change to runlevel 1.
    7. Did your script run?
       
  4. The scripts in /etc/init.d are can be invoked as "Kill" scripts or "Start" scripts. They are called with a stop parameter, when invoked as a "Kill" script and called with a start parameter when invoked as a "Start" script. These scripts should be structured as follows:

# sample script
case "$1" in
start)
   instructions for starting a service go here
;;
stop)
   instructions for stopping a service go here
;;
esac


    1. Using the format shown above, code a script that does the following:
      • when the script is called with a stop parameter, it should turn the screen background colour red and then clear the screen
      • when the script is called with a start parameter, it should turn the screen background colour green and then clear the screen
    2. Test your script and make sure that it works.
    3. Put a K link to your script in /etc/rc1.d and an S link to your script in /etc/rc2.d.
    4. Test your links. Change to runlevel 1; the screen should turn red. Change back to runlevel 2; the screen should turn green.

34.  Format, Check, Mount: Managing filesystems on a floppy


Notes:


  1. mount
    - used to insert a filesystem on a device such as a hard drive, floppy or cd-rom into the main filesystem tree.
    - can normally only be used by the superuser
    - the most common format of mount is: mount -t fstype device directory
    - /etc/fstab is the configuration file for the mount command
    - /etc/mtab normally contains a list of the filesystems that are currently mounted
    - eg:
    mount -t vfat /dev/fd0 /floppy
    - eg:
    mount -t ext2 /dev/ram2 /mnt
     

2.      umount - unmount; can unmount either the directory or the device
- eg:  umount /floppy OR umount /dev/fd0
 

  1. mkfs - creates a logical filesystem on a device
    - eg:  mkfs -t ext2 /dev/fd0
     
  2. fsck - check a filesystem (and optionally repair it)
     - eg:  fsck -t ext2 /dev/fd0
     
  3. sync - write any data in the filesystem cache out to disk
     

6.      du - display the amount of disk space used:
- eg:  du /etc
 

7.      df - show the amount of free space on filesystems that are mounted


Exercises:


  1. What entries exist in /etc/fstab for mounting floppies?
     
  2. What is the difference between /etc/fstab and /etc/mtab?
     
  3. What is displayed by the mount command without any parameters or options?
     
  4. Create an ext2 filesystem on a 3.5" floppy. ( mkfs -t ext2 /dev/fd0 )
     
  5. Try to mount this floppy using the command: mount /floppy
    Why doesn't this work?
     
  6. How do you check to see if the floppy is mounted?
     
  7. Use man to determine the purpose of the du command. Use du to report on the space used by the directory /usr.
     
  8. Use du to report on the space used on the floppy formatted in question 4.
     
  9. Use man to find out the purpose of the df command. Use df to report available space on the floppy in 1K blocks. ____________
     
  10. It is possible for a filesystem to run out of inodes even though there is still storage space available. What option of the df command will display information about free inodes. How many free inodes are available in /usr?
     
  11. What command flushes the contents of the disk cache out to the disk?
     
  12. Unmount the floppy and check the integrity of the filesystem. What command do you use?
     
  13. Try the following:
    • mount the floppy formatted in question 4
    • eject the floppy (do NOT unmount it first)
    • now unmount the floppy
    • put the diskette back in the drive and mount it again
    • what error messages do you get?
    • unmount the floppy
    • now use fsck to check the file system on /dev/fd0
    • mount the floppy again
    • do you still get error messages?

35.  Archiving and compressing


Notes:


Gzip:

  1. Large files can be gzipped the files to save space.
  2. The command to gzip the file readme is: gzip readme
    This will compress the readme file and save the result in a file called readme.gz.
  3. The command to gunzip the file readme.gz is: gunzip readme.gz
  4. Gzip supports 9 levels of compression; 1 being the fastest and least compressed; 9 being the slowest and most compressed; 6 being the default. To get the best compression, use the command: gzip -9 readme
     

Tar:

Tar is used to pack the entire contents of a directory or directories into a single file called a tarball which can then be backed up to tape, gzipped and saved, or transferred to another system. Tar preserves the entire directory organization including file ownership, permissions, links, and the directory structure. Tar stands for tape archive because it was developed to backup files on tape. Now, most of the Linux software available on the Internet is stored as gzipped tar files.

The most commonly used tar functions are:

  • c - create an archive
  • x - extract files from an archive
  • t - list the contents of an archive

Additionally, there are commonly used options:

  • v - verbose
  • f  filename - use the specified file
  • z - gzip/gunzip

Examples:
 

  1. Back |up the contents of the home directory for alterego (/home/alterego) in a tarball called a.tar on a floppy disk.
     
    mount /floppy
    cd /home
    tar -cvf /floppy/a.tar alterego
     
    Explanation:
    • Change to the parent of the /home/alterego directory.
    • Create a backup of alterego in the file /floppy/a.tar.
        
  2. Now, check the contents of the tarball that you just created.
     
    cd /floppy
    tar -tvf a.tar
     
  3. Back |up the contents of the etc directory in an archive called etc.tar . Make sure that the archive is created in your own home directory.
     
    cd /
    tar -cvf ~/etc.tar etc
     
    Explanation:
    • Change to the parent of the /etc directory.
    • Create a backup of etc in the file ~/etc.tar
       
  4. Back |up and compress the contents of the home directory into the tarball home.tgz on a floppy disk.
     
    mount /floppy
    cd /
    tar -cvzf /floppy/home.tgz home
     
    Explanation:
    • change to the parent of the /home directory
    • Create a compressed backup of home in the file /floppy/home.tgz.
       
  5. Now check the contents of the archive that you just created.
     
    cd /floppy
    tar -tvzf home.tgz
     
  6. Unpack the archive home.tgz on your floppy.
     
    cd /floppy
    tar -xvzf home.tgz
     
    Explanation:
    • change to the /floppy directory
    • unpack and unzip the tarball home.tgz


Exercises:


  1. Practice gunzip.
    • Find the file passwd.1.gz and copy it to your own home directory.
    • Gunzip this file.
  2. Unpack a tarball.
    • Find the archive: vtree.tgz and copy it to your own home directory.
    • Unpack the archive vtree.tgz .
    • What directories/files are created?
       
  3. More gzipping/gunzipping:
    • Gunzip the file vtree.1.gz . This file was created when you unpacked vtree.tgz.
    • Gzip all the files in your home directory.
       
  4. Create and unpack a tar archive of the directory /home.
    • Mount /floppy .
    • Change to the directory /home.
    • Create a compressed archive of your own home directory called /floppy/mine.tgz .
    • Change to the directory /floppy and unpack mine.tgz .
       
  5. More practice:
    • Change to the directory /var.
    • From this directory, create a tarball of the directory spool/mail called /floppy/mail1.tar
    • Change to the directory /var/spool.
    • From this directory, create a tarball of the directory mail called /floppy/mail2.tar
    • Change to the /floppy directory.
    • List the contents of mail1.tar ( tar -tvf mail1.tar ).
    • List the contents of mail2.tar.
    • What is the difference between the two tarballs? __________


Questions & Answers:


  1. Which command will give best compression?
    a.  gzip -1 lab10.html
    b.  gzip -9 lab10.html
     
     A or B
     
  2. Which command will display the contents of a gzipped file on the screen but leave the actual file unchanged?
    a.  gzip
    -c lab10.gzip
    b.  
    gzip -d lab10.gzip
     
    A or B

     
  3. Which command will create archive the labs directory in a tarball called labs.tar?
    a.  tar
    -cvf labs labs.tar
    b.  
    tar -cvf labs.tar labs
     
    A or B

     

4.  Which command will unpack the tarball labs.tar?
a.  tar -xf labs.tar
b.  tar -tf labs.tar

A or B
 
 


36.  Scheduling tasks with cron


Notes:


1.      Cron is used to automate periodic tasks (eg: backup the hard drive at every Sunday at 3 a.m. or email yourself a reminder about the Linux Users Group meeting the first day of every month)
 

2.      Users setup the configuration file for cron using the command: crontab

    • to create or modify the configuration file use: crontab -e
      This will alow you to edit your own crontab using vi
    • to view the contents of the file use: crontab -l
    • to delete the file use: crontab -r
       
  1. Your configuration file is stored in the directory: /var/spool/crontabs under your username.
     
  2. The crond daemon checks the crontab files every minute to determine if  a task should be launched in that minute.
     
  3. Each line in a crontab file has 6 fields:
    • minute
    • hour
    • day of the month
    • month
    • day of the week
    • command
       
  4. If the command produces output, the output will be sent to you in an email message.
     
  5. Example 1:
    19
      20   *   *   Sun   echo Study Linux
    Every Sunday, at 20:19, echo Study Linux (you will receive this as an email message)
     
  6. Example 2:
    13,18,23,28   5   *   *   Mon-Fri   /usr/bin/who
    Monday to Friday, at 5:13, 5:18, 5:23 and 5:28 execute /usr/bin/who
     
  7. Example 3:
    43   */2   1   *   *   echo Pay Bills
    On the first day of every month, every 2 hours at 43 minutes past the hour, echo Pay Bills.


Exercises:


  1. Setup a cron job to echo Study Linux every 30 minutes, Monday to Friday.
     
  2. Setup a cron job to echo Study Linux every hour on Saturday and Sunday.
     
  3. Setup a script that displays the date and then a list of everyone who is logged on. Run your script and make sure that it works. Setup cron to run the script you created on the first day of every month at 08:02.
  4. Setup a script called backup that echoes the message "You should backup now". Run your script and make sure that it works. Setup cron to run the script you created in question two the first day of every month at 07:17.
  5. When you are sure that this is working correctly, store the output from crontab -l in the file cronlist.
     
  6. Run crontab -r to delete all of your cron tasks.

37.  Examining System Logs


Notes:


1.      Syslogd controls the logging of messages from the kernel, various daemons, authorization events, etc.

2.      The configuration file for syslogd is /etc/syslog.conf

3.      On floppix, system logs are recorded on virtual console 8. Press [alt][F8] to view the logs.

4.      Note: some utilities create their own log files so some information that is not saved by syslog may still be logged.


Exercise:


This lab involves executing various commands and then checking in the log to see if the event was logged. System logs are most useful if you can identify normal and abnormal entries. So this is the time to look at normal activities and the log entries they generate. For each of the following, do the required action and then switch to virtual console 8 to view the log entry. Note: some activities may not generate log messages.

  1. Load floppix but do NOT login
    Switch to virtual console 8 to view the log messages.
    What types of activities are logged during system startup?
     

  1. What is the last entry in the log?
     

  1. Login using your own initials. What log entry (if any) was generated?
     

  1. Enter the command "su -" to become root. What log entry (if any) was generated?

  1. Determine your ip address (ifconfig). What log entry (if any) was generated?

  1. "telnet localhost". What log entry (if any) was generated?

  1. At the login prompt for the telnet session, login as alterego. What log entry (if any) was generated?

  1. Logout of the telnet session. What log entry (if any) was generated?

  1. Use vi to edit the file /etc/hosts.allow. This file and /etc/hosts.deny control which other systems are allowed to make certain types of network connections to your system. At the moment, no-one else is allowed to connect to your system but you can make a network connection to yourself. Currently the last line of this file reads "ALL: 127.0.0.1".  Change it to: "in.ftpd: 127.0.0.1". What log entry (if any) was generated when you edited this file?
     

  1. "telnet localhost". This time, what log entry (if any) was generated?
     

  1. Read the mail message(s) for root. What log entry (if any) was generated?
     

  1. Change the owner of  getme to alterego. What log entry (if any) was generated?

  1. "exit" from the root account. What log entry (if any) was generated?

  1. "ftp localhost"  and login as alterego. What log entry (if any) was generated?

  1. Download getme and quit. What log entry (if any) was generated?

  1. Send email to alterego. What log entry (if any) was generated?

  1. Create a crontab to echo Study Linux every minute. What log entry (if any) was generated?

  1. Wait one minute (until your crontab runs at least once). What log entry (if any) was generated?

  1. Delete the crontab. What log entry (if any) was generated?

  1. Change your password. What log entry (if any) was generated?

  1. Put floppix disk 1 in the floppy drive and mount it. What log entry (if any) was generated?
     

  1. Eject the floppy and then "umount /floppy". What log entry (if any) was generated?
     

FYI (For Your Information)

38.  Configuring syslogd

(From http://www.cert.org/security-improvement/implementations/i041.08.html)

 

Syslogd is a collecting mechanism for various logging messages generated by the kernel and applications running on UNIX operating systems.

Although this daemon is installed by default, its configuration should be adjusted to specify what messages are to be stored in what files or forwarded to another loghost on the local network. The default syslogd configuration usually does not reflect the full set of installed application programs and does not support the desired logging priorities.

 

39-41.      Security (setuid, setgid programs; tcpd, and inetd)

http://www.tldp.org/HOWTO/Secure-Programs-HOWTO/

 

http://www.linuxgazette.com/issue15/tcpd.html

 

http://www.tac.eu.org/cgi-bin/man-cgi?inetd+8