Linux Workbook
Linux Workbook
Geoffrey Robertson
[email protected]
1
Copyright c 2002 Geoffrey Robertson. Permission is granted to make and distribute ver-
batim copies or modified versions of this document provided that this copyright notice and this
permission notice are preserved on all copies under the terms of the GNU General Public Li-
cense as published by the Free Software Foundation—either version 2 of the License or (at your
option) any later version.
2
Contents
I Installing Linux 11
1 13
III Basics 27
4 Navigating the Filesystem 29
4.1 Basic Filesystem Commands . . . . . . . . . . . . . . . . . . . . . . 29
4.2 Exercise in navigating a filesystem . . . . . . . . . . . . . . . . . . . 29
4.2.1 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3
4 CONTENTS
IV Filesystem Basics 39
7 Using DOS floppies with mtools 41
7.1 mtools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
7.2 Exercise in using mtools . . . . . . . . . . . . . . . . . . . . . . . 41
7.2.1 mdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2.2 mcd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2.3 mtype . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2.4 mcopy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7.2.5 mdel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2.6 mformat . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.3 Further Information... rtfm . . . . . . . . . . . . . . . . . . . . . . . 43
7.3.1 usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.3.2 man pages . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.3.3 info pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7.3.4 usr/doc/mtools-3.9.1 . . . . . . . . . . . . . . . . . 44
8 Journaling filesystems 45
8.0.5 Gather information about your filesystems . . . . . . . . . . . 45
8.0.6 Convert the root filesystem to ext3 . . . . . . . . . . . . . . 45
V Rescue Disks 47
9 tomsrtbt 49
9.0 Some small Linux distributions . . . . . . . . . . . . . . . . . . . . . 49
9.1 Installing tomsrtbt onto a floppy . . . . . . . . . . . . . . . . . . . . 49
9.1.1 Install from an existing tomsrtbt floppy . . . . . . . . . . . . 49
9.1.2 Install from a tomsrtbt download . . . . . . . . . . . . . . . 49
9.2 Booting tomsrtbt . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
9.3 Explore the virtual consoles . . . . . . . . . . . . . . . . . . . . . . . 50
9.4 Command line gibberish . . . . . . . . . . . . . . . . . . . . . . . . 51
9.5 Replacing LILO in the mbr with tomsrtbt . . . . . . . . . . . . . . . 51
9.6 using fdisk with tomsrtbt . . . . . . . . . . . . . . . . . . . . . . . . 52
9.6.1 exercise using fdisk . . . . . . . . . . . . . . . . . . . . . . . 52
CONTENTS 5
VI Manipulating Text 55
11 Manipulating Text 61
11.1 Displaying Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
11.2 Create a text file and manipulate the text . . . . . . . . . . . . . . . . 62
11.3 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
12 File Compression 67
12.1 compress and uncompress . . . . . . . . . . . . . . . . . . . . 67
12.2 zip and unzip . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
12.3 gzip and gunzip . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
12.4 bzip2 and bunzip2 . . . . . . . . . . . . . . . . . . . . . . . . . 69
13 tar basics 71
13.1 tar—from the GNU man page . . . . . . . . . . . . . . . . . . . . . 71
13.2 Simple example: creating then extracting a tarball . . . . . . . . . . . 71
13.3 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
13.3.1 tar Function Letters . . . . . . . . . . . . . . . . . . . . . . 72
13.3.2 A few popular tar options . . . . . . . . . . . . . . . . . . . 72
13.4 Practical Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
IX Emacs 81
16 emacs tutorial 83
16.1 what to do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
16.2 emacs key naming conventions . . . . . . . . . . . . . . . . . . . . 83
16.3 A Few Essential Commands . . . . . . . . . . . . . . . . . . . . . . 83
16.4 Starting GNU emacs . . . . . . . . . . . . . . . . . . . . . . . . . . 84
16.5 Exercise: Breaking the Ice . . . . . . . . . . . . . . . . . . . . . . . 84
16.6 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
16.7 speedbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
16.7.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
16.8 the built in tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
16.8.1 Viewing Screens . . . . . . . . . . . . . . . . . . . . . . . . 88
16.8.2 Basic Cursor Control . . . . . . . . . . . . . . . . . . . . . . 88
16.8.3 Cancel the Current Command . . . . . . . . . . . . . . . . . 88
16.8.4 Disabled Commands . . . . . . . . . . . . . . . . . . . . . . 88
16.9 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.10Inserting and Deleting . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.10.1 Deleting characters . . . . . . . . . . . . . . . . . . . . . . . 89
16.10.2 Marking sections . . . . . . . . . . . . . . . . . . . . . . . . 89
16.10.3 Undo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.11Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.12Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
16.13Mode Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
X Inroduction 91
17 using vi 93
17.1 you must be able to use vi . . . . . . . . . . . . . . . . . . . . . . . . 93
17.2 writing a new file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
17.2.1 entering text . . . . . . . . . . . . . . . . . . . . . . . . . . 94
17.2.2 save your work . . . . . . . . . . . . . . . . . . . . . . . . . 94
17.2.3 quit from vi . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
17.3 view a file without changing it . . . . . . . . . . . . . . . . . . . . . 94
17.4 edit an existing file . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
17.5 emacs viper mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
17.6 want to know more? . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
17.7 Vi Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
18 File Permissions 99
18.1 File Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
18.2 Directory Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . 99
18.3 ls -l is your friend . . . . . . . . . . . . . . . . . . . . . . . . . . 100
18.4 Numeric Equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . 100
18.5 chown & chgrp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
18.6 Practical Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
18.6.1 File permissions and the root user . . . . . . . . . . . . . . . 102
18.6.2 File permissions and a normal user . . . . . . . . . . . . . . . 102
18.6.3 Umask exercises . . . . . . . . . . . . . . . . . . . . . . . . 103
CONTENTS 7
XI Programming 115
21 "Hello, world!" with gcc and vi 117
21.1 Make a directory for your c programmes . . . . . . . . . . . . . . . . 117
21.2 Write a ‘Hello, world! source file . . . . . . . . . . . . . . . . 117
21.3 Compile to the a.out binary executable with the GNU compiler . . . . 118
21.4 Running your executable . . . . . . . . . . . . . . . . . . . . . . . . 118
21.5 Write a C language program using vi . . . . . . . . . . . . . . . . . . 118
25 133
26 Cabling 135
26.1 Crimping RJ45 connectors onto Cat 5 cable . . . . . . . . . . . . . . 135
26.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
26.1.2 Crosover Cables . . . . . . . . . . . . . . . . . . . . . . . . 135
31 talk 155
31.1 talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
31.2 enabling talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
31.2.1 enable the service . . . . . . . . . . . . . . . . . . . . . . . . 156
31.2.2 restart the network daemon . . . . . . . . . . . . . . . . . . . 156
31.3 using talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
31.3.1 establishing a talk connection . . . . . . . . . . . . . . . . . 156
31.3.2 replying to a talk request . . . . . . . . . . . . . . . . . . . . 156
31.3.3 communicating with talk . . . . . . . . . . . . . . . . . . . . 156
31.3.4 finishing a talk session . . . . . . . . . . . . . . . . . . . . . 156
31.4 multi way talk sessions . . . . . . . . . . . . . . . . . . . . . . . . . 156
33 nfs 159
33.1 Server configuration—nfsd . . . . . . . . . . . . . . . . . . . . . . 159
33.1.1 The nfs and nfsd modules . . . . . . . . . . . . . . . . . . 159
33.1.2 Set exported directories in /etc/exports . . . . . . . . . 159
33.1.3 Services required to run an nfs server . . . . . . . . . . . . . 160
33.2 nfs client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
33.3 Practical Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
34 163
37 171
Part I
Installing Linux
11
Chapter 1
13
14 CHAPTER 1.
Chapter 2
15
16 CHAPTER 2. LINUX INSTALL: RH7.0
2.3 RTFM
Read the file called README on the first distribution CD.
Extensive documentation is on CD number 5. Open this document in your HTML
browser.
/cd5/RH-DOCS/index-en.html
The Official Red Hat Linux Getting Started Guide
The Official Red Hat Linux Installation Guide
The Official Red Hat Linux Reference Guide
If you don’t have Red Hat 7.0 CD number 5 then you can access all the documentation
on the distribution home pages. Read it.
C:\> d:
D:\> cd dosutils
D:\dosutils> rawrite
- D:\images\boot.img
- a:
2.6. STARTING THE INSTALLATION 17
2.7 installing
The Red Hat 7.0 installer presents the user with a series of screens with questions to be
answered and formes to be filled in. The following points might guide you through.
7. Format: /
8. Lilo configuration:
Create a boot disk
Boot from MBR
Winthing default
10. Time Zone Selection: Sydney Australia (not UTC if dual boot with WinThing)
13. Package Group Selection: Choose only the packages listed below and deselect
all the others:
Printer Support
X Window System
GNOME
Mail/WWW/News Tools
DOS/Windows connectivity
Graphics Manipulation
Multimedia Support
Networked Workstation
Dial-up Workstation
Network Management workstation
Authoring/Publication
Emacs
Development
Utilities
15. X Configuration: choose your video card and deselect “Use Graphical Login”.
Test your configuration.
login as you on another virtual terminal (ALT F2 say) login with your new
user name, explore and enjoy
try this:
– $ cd somewhere changes directory up to somewhere
– $ cd .. goes back
– $ ls -al lists the details of the files in ”.”
– $ man foo tells you about ”foo”
– $ apropos bar may tell you something about ”bar”
– try $ info and graze on the juicy info here
21
Chapter 3
ALIASES allow a string to be substituted for a word when it is used as the first word
of a simple command. The shell maintains a list of aliases that may be set and unset
with the ‘alias’ and ‘unalias’ builtin commands.
Example
An alias for the command ls -F may be set thus:
$ lf
bash: lf: command not found
$ unalias ll
Temporally unset an alias (use the original command):
$ \ls
23
24 CHAPTER 3. USING COMMAND ALIASES
$ ls
file0 file1* link.file@ mydir/
$ \ls
file0 file1 link.file mydir
$ ls
file0 file1* link.file@ mydir/
$ unalias ls
$ ls
file0 file1 link.file mydir
3.4 Exercise
In an interactive bash session:
1. Create an alias for ls -alF called ls.
2. Try it out on a few directories.
3. Check that $ ls makes ls revert to it’s normal unaliased behavior.
4. Delete the alias with the unalias command.
5. Check that it no longer works.
6. Append an alias to your .bashrc file thus:
$ echo -e " nalias ls=’ls -alF’ n" >> ˜/.bashrc
7. check that it got there: $ cat ˜/.bashrc
3.4. EXERCISE 25
Basics
27
Chapter 4
5.1 Startup
There are a few ways of starting Linux
5.2 Shutdown
There are a number of acceptable ways of shutting down Linux and two unacceptable
ways
Note that you must be root to shut down the system
33
34 CHAPTER 5. STARTUP AND SHUTDOWN
# useradd quincy
35
36 CHAPTER 6. SETTING UP USER ACCOUNTS
# passwd quincy
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
$ su - quincy
$ su -c ’vi /etc/passwd’
Password:
2. Add 1 a line for joe at the end. Be sure to add a name that does not already exist
and choose a UID and GID that are also new.
joe:!:510:510:Joe Blow:/bin/bash
joe:x:510
# mkdir /home/joe
$ su - joe
Password:
joe@mintie:˜$ pwd
/home/joe
joe@mintie:˜$
$ ls -l /usr/sbin/adduser
-rwxr-xr-x 1 root root 23466 Sep 12 06:08 \
/usr/sbin/adduser*
In Red Hat 7.0:
$ ls -l /usr/sbin/adduser
lrwxrwxrwx 1 root root 7 Feb 16 12:16 \
/usr/sbin/adduser -> useradd
# linuxconf &
2. Click on the little triangles to open up User accounts / Normal / User ac-
counts
3. Click the add button.
4. Add a login name and the full name.
5. Click the accept button.
6. Give fred a password.
7. Logon as fred from another terminal.
Filesystem Basics
39
Chapter 7
7.1 mtools
The mtools commands mimic DOS commands and are useful for working with DOS
files on a floppy disk—for example
mcd – change directory on the DOS disk
mcopy – copies DOS files between directories
mdel – deletes DOS files
mdir – lists DOS directories
mformat – adds DOS formating to a disk
mtype – cats a DOG file
a:\baz
a:\foo\bar\penguin.txt
a:\foo\bar\rubb.ish
41
42 CHAPTER 7. USING DOS FLOPPIES WITH MTOOLS
you are logged on as fred and you are in your home directory
7.2.1 mdir
Check what’s on the DOS floppy:
7.2.2 mcd
Move around the DOS floppy:
7.2.3 mtype
Look at the contents of a file:
7.2.4 mcopy
Copy a file to your current working directory:
7.2.5 mdel
Delete files from a DOS floppy:
7.2.6 mformat
format a floppy with a DOS file system:
7.3.1 usage
A mistake in the usage of a command may result in a usage message.
Here the incorrect option -xxx is used to provoke a usage response:
7.3.4 usr/doc/mtools-3.9.1
Change to the documentation directory and look at some of the documentation
[fred@fang fred]$ cd/usr/doc/mtools-3.9.1
[fred@fang mtools-3.9.1]$ ls
COPYING Changelog README Release.notes mtools.texi
[fred@fang mtools-3.9.1]$ cat README |less
...
Chapter 8
Journaling filesystems
2. Add a journal to the root filesystem using the default journal parameters (see
man tune2fs):
$ tune2fs -j /dev/hda5
45
46 CHAPTER 8. JOURNALING FILESYSTEMS
Part V
Rescue Disks
47
Chapter 9
tomsrtbt
DOS: tomsrtbt-1.7.218.dos.zip
49
50 CHAPTER 9. TOMSRTBT
– how do you save, where is the help? how do you stop it?
– intuitive huh? devils work, that’s why they call it 6 :)
– we’ll get back to it;
crank up another VC <Alt-F3> and log on;
start the emacs editor: # emacs ... oh *yes*, this looks goood!
type something: ‘‘throw your pants in the air, and pretend
you just don’t care’’;
god uses this editor for all her really important work;
Close you emacs session with C-X C-C (that’s a Control X followed by a Con-
trol C.
move around between the various virtual terminals by pressing <Alt-F2>,
<Alt-F3>, <Alt-F4>
change back to your original login shell on VC-1 by pressing <Alt-F1>
3. Change the root of the filesystem to be the partition you just mounted and start a
shell from the system on the hard disk:
52 CHAPTER 9. TOMSRTBT
# lilo
5. Kill the shell running from the system on the hard drive:
# exit
The system should now boot using LILO from the hard drive.
Alterntive method, enter: /mnt/sbin/lilo -r /mnt
# mount
...
/dev/fd0 on /fl type msdos (rw)
9.7. USING TOMSRTBT TO EDIT A FILE ON A DATA FLOPPY 53
# cd /fl
# ls
Add a directory and change to it:
# ce answers.txt
Answer the questions in the section headed Questions below by typing the an-
swers into the file answers.txt and save it.
54 CHAPTER 9. TOMSRTBT
9.8 Questions
Answer these questions by typing the answers into a file created on a floppy disk using
Chet’s emacs.
1. Which Linux kernel does tomsrtbt use? (Hint: # dmesg | more)
2. What is different about the sbin directory as compared with the other first level
directories?
Manipulating Text
55
Chapter 10
57
58 CHAPTER 10. UNIX AND DOS LINE ENDINGS
UNIX to DOS
sed: $ sed ’s/$/ˆM/’ unixfile.txt > dosfile.txt
Note: the ˆM is produced by C-V C-M
emacs: M-% C-q C-j RET C-q C-m C-q C-j RET !
Note Add a Control-Z at the end of the file in emacs with C-q C-z.
DOS to UNIX
tr: $ tr -d ’\15\32’ < dosfile.txt > unixfile.txt
emacs: First open the file in emacs using the find-file-literally option:
$ emacs
M-% find-file-literally
Find file literally: ˜/my.MS_DOG.txt
M-% C-q C-m RET RET !
$ cat >text.unix
dum de
dum
ˆD
View it: (check out $ man od)
$ od -bc text.unix
0000000 144 165 155 040 144 145 012 144 165 155 012
d u m d e \n d u m \n
Convert the line endings with sed:
10.1. TEXT FILES ON VARIOUS OPERATING SYSTEMS 59
$ od -bc text.dos
0000000 144 165 155 040 144 145 015 012 144 165 155 015 012 032
d u m d e \r \n d u m \r \n 032
Open emacs.
Visit the MS-DOG formatted file:
10.2 Questions
Answer these questions by typing the answers into a file created on a floppy disk using
Chet’s emacs.
1.
Chapter 11
Manipulating Text
$ wc -l letters
Display the file using cat:
61
62 CHAPTER 11. MANIPULATING TEXT
$ su -c ’tail -f -n5 \
/var/log/messages’
List the first 12 lines with line numbers:
11.3 Questions
1. What is the token used to add (append) to a file?
2. What command would print the contents of the file hello.c to the screen?
3. How can you use cat to copy the file one.a to the file two.a?
4. How do you determine how many words there are in a file? (see $ man wc)
5. The file a.file contains a list of products, one per line. What command would
give a count of the number of products?
64 CHAPTER 11. MANIPULATING TEXT
6. What command would print a list of the words beginning each line of the file
called stuff in reverse alphabetical order? (hint: try $ man sort)
8. If a file is made up of lines with fields separated by colons, how would you save
all of the third fields to a file called thirds.text?
George Pitman
Jenni Penny
Joe Blow
Mary Contrary
Antonia Lexis
65
Chapter 12
File Compression
References Read the man pages for compress, uncompress, zip, unzip, gzip,
gunzip, bzip2, bunzip2, funzip, zipcloak, zipgrep, zip-info,
zipnote, zipsplit, zcat, bzcat, zless.
Instructions: Read through these notes and do the practical exercises in each section.
File compression is used to minimise the amount of storage space a file occupies and to
reduce the time it takes to be transmitted over a network. Commonly used on archived
files for backup and long term storage.
$ ls -l man.txt
-rw-r--r-- 1 geoffrey geoffrey 30095 May 13 18:55 man.txt
compress it:
$ ls -l man.txt
-rw-r--r-- 1 geoffrey geoffrey 12874 May 13 18:55 man.txt.Z
67
68 CHAPTER 12. FILE COMPRESSION
– WinNT
– Atari
– Mac OS
– VMS
– UNIX
– OS/2
– Amiga
See also funzip, zipcloak, zipgrep, zip-info, zipnote and zipsplit.
$ ls -l gzip.txt
-rw-r--r-- 1 geoffrey geoffrey 18307 May 13 22:19 gzip.txt
compress it:
$ ls -l .txt
-rw-r--r-- 1 geoffrey geoffrey 6404 May 13 22:19 gzip.txt.gz
View the compressed file with zcat:
$ gzip -l gzip.txt.gz
compressed uncompr. ratio uncompressed_name
6404 18307 65.1% gzip.txt
Uncompress the file:
$ ls -l bzip2.txt
-rw-r--r-- 1 geoffrey geoffrey 19367 May 13 22:56 bzip2.txt
compress it:
$ ls -l bzip2.txt.bz2
-rw-r--r-- 1 geoffrey geoffrey 6469 May 13 22:56 bzip2.txt.bz2
View the compressed file with zcat:
tar basics
71
72 CHAPTER 13. TAR BASICS
13.3 Options
13.3.1 tar Function Letters
The tar options must include one and only one of the following function letters:
-A, --catenate, --concatenate append tar files to an archive
-c, --create create a new archive
-d, --diff, --compare find differences between archive and file system
--delete delete from the archive (not for use on mag tapes!)
-r, --append append files to the end of an archive
-t, --list list the contents of an archive
-u, --update only append files that are newer than copy in archive
-x, --extract, --get extract files from an archive
2. Archive your home directory (say as a backup) into a compressed file called
mybackup.tar.gz. List the files in your tarball. Then extract the tarball into the
/tmp directory.
Move outside the directory you are going to archive (avoid recursion) then
make a tarball in your current working directory:
$ cd /tmp
$ tar -czvf mybackup.tar.gz ˜
List the files in the archive:
$ tar -ztvf mybackup.tar.gz
Extract the archive:
$ tar -zxvf mybackup.tar.gz
Inspect the extracted files: $ tree
Part VIII
Installing Software
73
Chapter 14
|-- wingdingfont
| ‘-- CVS
‘-- xml
‘-- CVS
$ ls wv-0.6.7
config.h.in iconv/ sep.c
config.sub* install-sh* shd.c
configure* laolareplace.c sprm.c
configure.in laolareplace.old.c sprmtest
$ ls
MS_Word_File.doc
79
80 CHAPTER 15. USING RPMS AND THE REDHAT PACKAGE MANAGER
Part IX
Emacs
81
Chapter 16
emacs tutorial
16.1 what to do
Read the information in sections 2 and 3.
Practice opening GNU emacs at a text console and in an X terminal (section 4).
Work through the practical exercise in section 5.
answer the questions in section 6.
M-x either:
hold down Meta or Alt key while pressing the x key.
or press and release the
key then press x key.
C- or C-/ undo
83
84 CHAPTER 16. EMACS TUTORIAL
$ emacs
$ startx
3. In an X terminal type the command to start emacs. Note the ampersand follow-
ing the command which runs the program in the background.
$ emacs &
4. Start another copy of emacs from the Window Manager’s menu system.
5. Close your emacsen either by killing them or C-x C-c.
Place your cursor in the middle of a line. Delete five characters to the left with
your Backspace key then delete five characters to the right with C-d.
Get back your ten deletions by pressing C- ten times.
Try a forward search:
– If you dont have the emacs tutorial open then open it with C-h t
– Move the curser to very top of the tutorial document.
– Type C-s to open the I-search:
– type the letter “b”. Note that the cursor has moved to the first letter b in the
document.
– Type the letter “l”, then an “e”. Note how the search progresses.
– Cancel it with C g
Save the file in your home directory with a new name: C-x C-w and type the
name of the file say /junk.text.
Delete a line: Move the cursor the start of a line and press C-k.
Save the altered file: C-x C-s.
Close emacs C-x C-c.
86 CHAPTER 16. EMACS TUTORIAL
16.6 Questions
1. What keys are used to delete characters to the right of the cursor?
10. How do you kill a block of marked text and copy it to the kill ring?
16.7 speedbar
The emacs speedbar is useful for browsing the info system.
M-x Info-speedbar-browser
16.7.1
88 CHAPTER 16. EMACS TUTORIAL
2. When the cursor is placed on the last line of the page what happens when your
press C-n?
4. What key combinations move the cursor to the beginning or end of a line?
7. Why is it better to learn to use the control keys rather than use the arrow keys?
9. Which mouse button is used to move the thumb in the scroll bar?
2. What are the choices you are given if you use a disabled command key combi-
nation?
16.9. WINDOWS 89
16.9 Windows
1. C-x 1 does what exactly?
16.10.3 Undo
1. What does C-x u do?
2. What other key combination does the same as C-x u?
16.11 Files
16.12 Buffers
16.13 Mode Line
90 CHAPTER 16. EMACS TUTORIAL
Part X
Inroduction
91
Chapter 17
using vi
Document Description: Exercise in using the vi (VIsual) editor and learning a few
relevant commands.
References :
note1 [ESC] means press the escape key, redundant [ESC] key-presses just beep at
you
note2 Generally you will use a vi clone like elvis or vim or emacs viper mode
93
94 CHAPTER 17. USING VI
/* first c using vi */
#include <stdio.h>
main()
{
printf("hi, vee-eye");
return 0;
}
LEAVING vi
CURSOR POSITIONING
TEXT MODIFICATION
PATTERN SEARCHING
NOTES:
ESC represents the ESC key. Press the ESC key when
98 CHAPTER 17. USING VI
CTRL- represents the CTRL key. Hold the CTRL key and
press the following key simultaneously.
CURSOR POSITIONING
TEXT MODIFICATION
PATTERN SEARCHING
MISCELLANEOUS
http://vertigo.hsrl.rutgers.edu/ug/vi_qref.html
Chapter 18
File Permissions
99
100 CHAPTER 18. FILE PERMISSIONS
pebbles pebbles
bambam bambam
$ ls -l rubbles*
-rwxrw-r-- 1 barney flinstones 16345 Nov15 08:45 rubbles.txt
$
FILE TYPE Read Write Execute Read Write Execute Read Write Execute
(r) (w) (x) (r) (w) (x) (r) (w) (x)
r w x Value
− Normal File
− − − 0
d Directory
− − x 1
− w − 2
− w x 3
r − − 4
r − x 5
r w − 6
r w x 7
# ls -l rubble.txt
-rw-rw-r-- 1 barney flinstones ... rubble.txt
# ls -l rubble.txt
-rw-rw-r-- 1 barney flinstones ... rubble.txt
# ls -l rubble.txt
-rw-rw-r-- 1 barny flinstones ... rubble.txt
note 1: Every object in the filesystem has an owner ID and a group ID which are by default the
ID’s of the process which created it.
105
106 CHAPTER 19. INODES AND LINKS
The following should show you that they they are the same file.
add some text into a.file $ echo "this is going into the in a.file" >> a.file
look in a.file $ cat a.file ... the text went in?
look at the c.file – $ cat c.file – it’s a soft link to a.file
nuke the a.file – $ rm a.file
take another look at the c.file – $ cat c.file nothing to link to now
but what about the b.file – $ cat b.file
geoffrey:x:500:
joe:x:501:
jbloggs:x:502:
jblogg:x:503:
student::504:geoffrey,joe,jbloggs,jblogg
check that you are in the group:
$ id
uid=500(geoffrey) gid=500(geoffrey) groups=500(geoffrey)
logout and log back in to register the change in the /etc/group file and check your id
again:
$ id
uid=500(geoffrey) gid=500(geoffrey) groups=500(geoffrey),504(student)
change the group id of the file a.file to student
$ chgrp student a.file
$ ls -l
total 3
-rw-rw-r-- 2 geoffrey student 18 Sep 1 17:14 a.file
see if jbloggs can use the file
$ su jbloggs
Password:
[jbloggs$ echo "jbloggs waz here" >>a.file
[jbloggs$ exit
$ cat a.file
this is in a.file
jbloggs waz here
108 CHAPTER 19. INODES AND LINKS
Chapter 20
109
110 CHAPTER 20. MOUNTING FILE SYSTEMS
2. Any files existing at the mount point will be hidden when a volume is mounted at the
point.
3. File system types include:
Using this table the mount commands may be abbreviated. Note also that users
have access to mounting the floppy and cdroms.
Mount a floppy
The mount command with no arguments also will report the currently mounted
volumes.
$ mount
/dev/hda6 on / type ext2 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /mnt/disk type vfat (rw)
$ du
24 ./vmware/win2000
961136 ./vmware/nt4
961164 ./vmware
20 ./.netscape/cache
4 ./.netscape/archive
968164 .
Disk filesystem disk space usage
$ df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda6 3755460 3041736 522956 86% /
/dev/hda1 2044240 614664 1429576 31% /mnt/disk
$ df
Look at the dynamic mount table:
Check the disk usage for your home directory (the -h option gives a human
readable format of the output:
$ du -h ˜
20.2.2 Floppy disk exercise
Note: If you have an automount demon running it may mount your floppy disk auto-
matically (check with mount. In this case first unmount the floppy disk.
List the directory /mnt/floppy: $ ls -la /mnt/floppy
place an MSDOS formatted floppy in the fd0 device (a.k.a. a: drive);
mount the floppy so that it can be accessed from the mount point /mnt/floppy
(note that to use the mount command in it’s full form you may need to be root):
$ cd /mnt/floppy
make a subdirectory on it called /mnt/floppy/asubdir and use cat or vi
to create a test file on the floppy
umount the floppy before removing it. Note that the floppy must not be in use
when unmounting it.
$ cd
$ umount /mnt/floppy
physically remove the floppy.
or as an ordinary user
$ cd /mnt/cdrom
explore the CDROM
umount and eject the CDROM before removing it:
$ cd
$ eject
physically remove the CDROM.
$ cd /mnt/windows
explore the widows file system
114 CHAPTER 20. MOUNTING FILE SYSTEMS
Part XI
Programming
115
Chapter 21
$ ls
a.out hi.c
$ a.out
bash: a.out: command not found
Check the permissions to see that the ’x’ bit is set:
$ ls -l
-rwxrwxr-x 1 yourname yourname 4150 Mar 9 17:27 a.out
Why doesn’t it run? By default the current directory ’.’ is not in the path. Check
it $ echo $PATH; you will see no ’.’.
To run it you have to give the path to the file:
$ ./a.out
Hello, world!
return 0;
}
Chapter 22
$ cd
Make a directory for your programmes:
$ cd c.progs
119
120 CHAPTER 22. ”HELLO WOULD!” WITH GCC
$ ls
a.out hi.c
$ a.out
bash: a.out: command not found
Check the permissions to see that the ’x’ bit is set:
$ ls -l
-rwxrwxr-x 1 yourname yourname 4150 Mar 9 17:27 a.out
Why doesn’t it run? By default the current directory ’.’ is not in the path. Check
it $ echo $PATH; you will see no ’.’.
To run it you have to give the path to the file:
$ ./a.out
Hello, world!
C-x C-w
hi.emacs.c
Save your emacs edits at any time with C-X C-S.
Compile your source from inside emacs: (M-! means either Alt-! or [ESC] then
!, the shell command is then typed into the mini-buffer window)
22.6. WRITE OUT WHAT THESE 15 COMMANDS DO 121
M-!
Shell command: gcc -o hello hi.emacs.c
Run the program with output to a new buffer:
M-!
Shell command: ./a.out
Close the other emacs window:
C-x 1
Save your file and exit emacs:
C-x C-C
ESC !
C-SPACE
C-X 0
C-X 1
C-X 2
C-X 3
Networking
123
Chapter 23
23.1 Overview
There are several layers that have to be built in order to setup a Local Area Network.
1. Load the kernel module (driver) for the NIC (ethernet card) card that is installed
on the system.
On systems using Plug and Play hardware the modudules will be automatically
loaded. However, in the case of legacy hardware such as the NE2000 NIC this
has to be done by hand.
# netconfig
125
126 CHAPTER 23. LAN SETUP IN ROOM C222 (RH73)
Exercise:
1. Check that the module used for your Network Interface Card is loaded:
# lsmod
Unload the module:
# lsmod
Module Size Used by
lockd 31176 1 (autoclean)
sunrpc 52964 1 (autoclean) [lockd]
ne2k-pci 4652 1 (autoclean)
8390 6072 0 (autoclean) [ne2k-pci]
Install a loadable kernel module: (if there was a NE2000 ISA NIC)
# vi /etc/modules.conf
alias parport_lowlevel parport_pc
alias sound-slot-0 maestro3
alias eth0 ne
options ne io=0x300 irq=5
˜
˜
Now when eth0 is used the ne module will load automatically using the pa-
rameters shown.
Unload a kernel module:
# rmmod ne
depmod handles dependency descriptions for loadable kernel modules. Creates
a module dependency list. $ man depmod
for details.
Divert the output to STDOUT for viewing:
127.0.0.1 localhost
192.168.222.254 foozle.c222 foozle
192.168.222.253 sparkie.c222 sparkie
Exercise
Setup a static IP address for your system. Use netconfig then neat. Explore neat
thoroughly.
130 CHAPTER 23. LAN SETUP IN ROOM C222 (RH73)
Chapter 24
131
132 CHAPTER 24. BASIC NETWORK COMMANDLINE TOOLS
Chapter 25
133
134 CHAPTER 25.
Chapter 26
Cabling
26.1.1
If you hold the RJ45 connector facing you (as if you were going to plug it into your
mouth) with the lock tab on the top, then the pins are numbered 1 to 8 from left to right.
_____________________
brown 8-------| |
white / brown 7-------| |
orange 6-------| _______________ |
white / blue 5-------| | | TAB on top
blue 4-------| |______________ |
white / orange 3-------| |
green 2-------| |
white /green 1-------|_____________________|
135
136 CHAPTER 26. CABLING
Chapter 27
27.1 configuration
27.1.1 configuration files
/etc/HOSTNAME the host name for the localhost
/etc/resolv.conf stipulates how host names are resolved
/etc/hosts lookup table matching host names to IP addresses
/etc/services table of network services and port numbers
/etc/inetd.conf controls which services are available; xinetd is an alternative
system
/etc/xinetd.conf and the files in /etc/xintd.d/ control which services are avail-
able on RH7.0 and up
/etc/host.conf remote host lookup order.
27.1.2 /etc/resolv.conf
resolver uses the configuration file /etc/resolv.conf provide access to the Internet Do-
main Name System.
$ cat /etc/resolv.conf
search fernbank
nameserver 61.8.0.2
nameserver 61.8.0.5
137
138 CHAPTER 27. NETWORKING TEXT TOOLS
27.1.3 /etc/host.conf
This configuration file controls the host lookup order. In this example the resolver will
search all of the /etc/hosts file first then use bind (DNS lookup).
$ cat /etc/host.conf
order hosts,bind
multi on
27.1.4 /etc/hosts
In a small network host names may be resolved into IP addresses form the file /etc/hosts.
e.g.
$ cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.222.1 foozle.zork foozle
192.168.222.101 box1.zork box1
192.168.222.102 box2.zork box2
192.168.222.103 box3.zork box3
...
192.168.222.116 box16.zork box16
27.1.5 /etc/HOSTNAME
The hostname is read at boot time by the boot scripts from the file /etc/HOSTNAME
(RedHat) or /etc/hostname (Debian) on some systems. This file may be edited to
permanently change the hostname. The hostname may be displayed:
# hostname
foozle.zork
or changed temporarily with this command:
# hostname blahblah
27.1.6 installing a NIC
Normally a plug and play Ethernet Adapter will be automatically detected and set up
during installation. A legacy ISA adapter may have to be compiled into the kernel or
loaded as a module.
Check which modules are loaded (here a netgear PCI and a NE2000 NIC are
installed)
$ lsmod
tulip 30264 1
ne2k-pci 34757 1
A legacy NE2000 ISA card would be loaded thus: (ymmv)
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:40:05:46:7F:32
inet addr:192.168.42.1 Bcast:192.168.42.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24076 errors:0 dropped:0 overruns:0 frame:0
TX packets:93529 errors:0 dropped:0 overruns:0 carrier:0
collisions:38 txqueuelen:100
Interrupt:9 Base address:0x9500
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:3924 Metric:1
RX packets:29552 errors:0 dropped:0 overruns:0 frame:0
TX packets:29552 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
ppp0 Link encap:Point-to-Point Protocol
inet addr:61.8.18.98 P-t-P:203.9.190.192 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:5151 errors:12 dropped:0 overruns:0 frame:12
TX packets:4591 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
# tcpdump
tcpdump: listening on all devices
01:20:56.210331 eth0 > lollipop.fernbank.ssh >
mintie.fernbank.1870: P 3624801409:3624801517
(108) ack 2624831152 win 32120 <nop,nop,timestamp
61941018 276985734> (DF) [tos 0x10]
....
....
298 packets received by filter
27.3. CHECKING AND TESTING 141
27.3.4 ping
ping is used to check if a particular IP address is accessible and to check the timing
and reliability of the connections:
check the connection to the ethernet card
1. Check that the /etc/hosts file has entries for the loopback address and the
hosts on the network.
[fred@box3 fred]$ su -
Password:
[root@box3 root]# vi /etc/hosts
# route
Add a default route if it does not exist:
27.8 exercise
After this exercise you should be able to:
telnet a remote host
copy files from a floppy to your home directory on the remote host
make a tarball of a group of files
use FTP to transfer files between hosts
compile a c program
send an email to a user on the local network
add an attachment to an email
telnet into the remote host
copy all the files on a floppy to your home directory on the remote host
tar and compress the files now in temp into a tarball called files.cvfz
144 CHAPTER 27. NETWORKING TEXT TOOLS
Instructions:
read through these notes and man telnet
telnet into some hosts where you have user accounts
28.1 warning
Hosts connected to an untrusted network may be vulnerable to cracking and various
exploits should they leave the telnet service open. Using a secure shell such as ssh is
safer in a hostile environment.
28.3 exercise
logon to the remote host—it should go something like this (If foozle is not in
your /etc/hosts file then either add it or use the ip address):
145
146 CHAPTER 28. LOGIN TO A REMOTE HOST USING TELNET
29.1.1 Notes
It in not generally possible or advisable to use ftp while logged on as root;
ftp transmits passwords and data in plain text, so for untrusted networks (inter-
net) use anonymous ftp or scp.
147
148 CHAPTER 29. TRANSFER FILES BETWEEN HOSTS USING FTP
29.2.1 Exercise 1
Create two files, one on the local host and one on the remote host, then copy each of
the files to the other computer.
Create a file on the local host:
put the file local.file from the local host to the remote host.
get the file remote.file from the remote host to the local host:
29.2.2 Exercise 2
Establish a telnet session with the remote host;
copy all the files on the floppy disk mounted on the remote host to a directory in
your home directory on the remote host;
geoffrey@zipperii:˜$
student@remotebox:˜$ ls -l
student@remotebox:˜$ cat freddy.local
5. Make a copy of the file on the remote host called <username>.remote and
append something to it:
freddy@localbox:˜$ ls -l
freddy@localbox:˜$ cat freddy.remote
freddy@localbox:˜$ diff freddy.local freddy.remote
154 CHAPTER 30. USING SECURE SHELL—SSH
Chapter 31
talk
31.1 talk
Talk is a visual communication program which copies lines from your terminal to that
of another user. talk allows the user to have a two way chat session with another user.
A typical talk session could look like this:
[Connection established]
pretty good... and your self?
okay
bye robbo
|------------------------------------------------------|
Hi Geoffrey, how are you?
i’m excellent. but i’m very busy i’ll talk to
you later
cu later
g
The screen divides into two and each person types in the top half and reads what the
other person is typing in the bottom half.
155
156 CHAPTER 31. TALK
157
158 CHAPTER 32. NETWORK FILE SYSTEM—NFS
The modules nfs, lockd and sunrpc should be loded on demand when mounting.
Check before and after with:
# lsmod
and
# ps aux |grep rpc
Chapter 33
nfs
References Read the man/info pages for nfs, nfsd, mountd, expotrfs, showmount,
nfsstat, nhfsstone.
# lsmod
Module Size Used by
nfs 76800 0 (unused)
nfsd 69984 0 (unused)
lockd 52336 0 [nfs nfsd]
sunrpc 62448 0 [nfs nfsd lockd]
...
159
160 CHAPTER 33. NFS
This example shows the /tmp directory may be nfs mounted by any host on the
192.168.1.0 C-class network.
# exportfs
/tmp 192.168.1.0/255.255.255.0(ro)
Export all entries in /etc/exports:
# export -a
Un-export all entries in /etc/exports:
# showmount
Hosts on lapdog2:
192.168.1.2
The modules nfs, lockd and sunrpc should be loded on demand when mounting.
Check before and after with:
# lsmod
and
# ps aux |grep rpc
163
164 CHAPTER 34.
Part XIII
Graphics
165
Chapter 35
The Gimp
The Gimp (Gnu Image Manipulation Program) provides an easy way using script-fu
to produce cool and crufty Logos suitable for display on web pages.
35.1 Documentation
Explore the documentation.
Users manual:
– Online: http://manual.gimp.org
– Dead tree: GIMP The Official Handbook CORIOLIS Press
Web page: http://www.gimp.org
Tutorials: http://www.gimp.org/tut-basic.html
Man page: $ man gimp
167
168 CHAPTER 35. THE GIMP
Figure 35.1: The Gimp Toolbox Figure 35.2: Selecting a Logo script
3. Select some appropriate options. See Figure 35.3 for the options chosen to give
a simple black and white logo.
4. Right click on the image and choose File / Save As. For a webpage pick a low
resolution compressed format like jpeg or png. Figure 35.4 shows a finished
logo.
Figure 35.3: Alien Neon Options Figure 35.4: Web Page Logo
Chapter 36
36.1 documentation
Take a quick look at the documentation.
Man page:$ man xfig
Users manual: Start netscape and enter the URL
file:/usr/X11R6/lib/X11/xfig/html/index.html
PDF manual: $ xpdf /usr/X11R6/lib/X11/xfig/xfig.pdf &
PDF xfig-howto: $ xpdf /usr/X11R6/lib/X11/xfig/xfig-howto.pdf
&
36.2 display
A VGA screen resolution of 640x480 does not give sufficient real estate to run xfig. If
X is setup correctly increase the resolution by pressing Cntl-Alt-keypadminus. Screen
resolutions may be set up using the setup / xconfigurator or XF86Setup utilities. If
all else fails use the virtual screens to use the off screen menus. Resize xfig to best fit
your screen.
36.3 starting
Start a new xfig figure by entering at the command line of an xterm:
$ xfig foo.fig.
The xfig utility should load and display.
Set the units to metric. Click mouse button 3 in the box at the intersection of the
rulers near the top right corner.
Explore the menus. Find out how to save, print and open a file. Look at the help
169
170 CHAPTER 36. XFIG: VECTOR DRAWING
36.4.2 draw
See Figure 1 below. Draw a picture of an egg in a truck on a bumpy road. For detailed
help see the html howto. Save your drawing.
rectangle: Select the rectangle button; click left; move; click left again.
move: Move the rectangle a bit. Select the move button; left click on a handle; move
the object then left click again.
resize: Enlarge the rectangle a bit. Select the resize button; left click on a corner, move
to resise and left click again.
splines: Draw a bumpy road. Select a spline button: click; click; click.
rotate: Select ellipse button; left click move ane click again; edit button to edit the
pattern and line thickness; rotate button to rotate.
text: Select the button labled T . Select the point size and font then click where you
want the text placed and start typing.
36.4.3 draft
See Figure 2 below. Draw a circuit diagram using library parts. Select the library
button and place a few parts from the Logic library. Connect the parts.
Figure 1 Figure 2
Chapter 37
171