Professional Documents
Culture Documents
MSIT - 3A
Linux Internals
Kuvempu University
Shankaraghatta, Shimoga District, Karnataka
No Part of this Book may be reproduced in any form or by any means without the written permission from Universal Education Trust, Bangalore.
All Product names and company names mentioned herein are the property of their respective owners.
NOT FOR SALE For personal use of Kuvempu University IT - Programme Students only.
Corrections & Suggestions for Improvement of Study material are invited by Universal Education Trust, Bangalore. E-mail : info@uetb.org
Printed at :
LINUX INTERNALS
(MSIT - 3A)
: Contributing Authors :
Smt. K. Roopa
Lecturer, Dept. of C.Sc. & Engg. JNNCE, Shimoga - 577204
Contents
Chapter 1 INTRODUCTION 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 Introduction and Objectives........................................................ Unix and Linux: Features ......................................................... Unix System Architecture ........................................................ Unix Philosophy ...................................................................... What is Linux? ........................................................................ Using a Linux System: Login .................................................... Linux Command Line .............................................................. Logging Out ........................................................................... Command Syntax .................................................................... Files ...................................................................................... Linux Directories...................................................................... File System Organization............................................................ Creating Files with cat............................................................... Displaying Files Contents with cat.............................................. Deleting Files with rm .............................................................. Unix Command Feedback .......................................................... Copying and Renaming Files with cp and mv .............................. Filename Completion ................................................................. Command History .................................................................... Summary.................................................................................. Check Your Progress................................................................. 1 1 2 3 4 4 5 5 6 6 6 7 7 10 10 11 11 11 12 12 12 13
VI
Chapter 2 LINUX COMMANDS 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12
Chapter 1 - Introduction
18 18 19 21 22 24 27 27 28 28 30 30 31 31
Introduction and objectives ........................................................ Basic Linux Commands............................................................. Help commands........................................................................ General commands.................................................................... File management commands...................................................... Finding files.............................................................................. Linux Files and File Permission................................................... File names and permission characters.......................................... Examples on files...................................................................... Setting Keystrokes.................................................................... Keys and terminal configuration ................................................. Summary.................................................................................. Check Your Progress.................................................................
Chapter 3 PROCESSES 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 Introduction and objectives......................................................... Looking at Processes................................................................. Process IDs............................................................................. Viewing Active Processes.......................................................... ps Output Formats..................................................................... Killing a Process....................................................................... Creating Processes................................................................... Creating Using system()............................................................ Creating Using system calls fork, exec..................................... Creating by Calling fork............................................................. Creating by Using the exec Family.............................................. Creating by Using fork and exec Together................................... Process Scheduling.................................................................... Signals..................................................................................... Some Linux daemons................................................................. popular daemons....................................................................... Zombie Proces.......................................................................... Threads.................................................................................... 37 37 38 38 39 39 41 42 42 43 43 44 45 45 46 47 48 50 51
MSIT 3A Linux Internals 3.18 Processes Vs. Threads.............................................................. 3.19 Summary.................................................................................. 3.20 Check Your Progress................................................................. Chapter 4 SHELL PROGRAMMING 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 Introduction and Objectives........................................................ Creating a shell script................................................................ Meta characters........................................................................ Positional Parameters and Shell Variables.................................... Built-in shell commands and variables.......................................... Iteration, control and if statements.............................................. Shell operators ........................................................................ The test Command.................................................................... An example script..................................................................... Environment Variables .............................................................. Summary.................................................................................. Check Your Progress.................................................................
VII
52 53 54
60 60 61 62 63 64 66 68 69 71 72 73 74
Chapter 5 FILE SYSTEM 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 Introduction and Objectives ....................................................... Filesystem Overview ................................................................ Types of Files........................................................................... Directory pointer....................................................................... Directory Hierarchy ................................................................. Pathnames .............................................................................. Current Directory ..................................................................... Dot (.) and DotDot(..) .............................................................. Moving and Copying Files ......................................................... Removing Files ........................................................................ Operations on Directories ......................................................... Inodes .................................................................................... Options of Inodes ................................................................... Links ...................................................................................... Hard links ............................................................................... 79 79 80 80 83 83 84 85 85 86 86 87 87 88 88 89
VIII
5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 5.23 5.24 5.25 5.26 5.27 5.28 5.29 5.30
Chapter 1 - Introduction
Soft links ................................................................................. Access Control and UID .......................................................... Categories of Access Control .................................................... Access Control Example ........................................................ Changing Access Previleges: hmod............................................ chmod symbolically .................................................................. chmod numerically ................................................................... umask Masking Privileges ......................................................... Filesystem Structure ................................................................. /etc/fstab - Example ................................................................ Special Files - /dev ................................................................ Special Files - /proc ............................................................... Mounting Additional Volumes .................................................... Mounting shared filesystems ..................................................... Summary ................................................................................ Check Your Progress................................................................
89 90 91 91 91 92 92 92 93 93 93 94 94 95 95 96
Chapter 6 FILE SYSTEM ADMINISTRATION 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 6.13 6.14 6.15 6.16 6.17 Introduction and objectives ........................................................ Inode in depth ......................................................................... Inode table entry ...................................................................... Links: relationship with inode ..................................................... Hard links ............................................................................... Soft links ................................................................................. Non-native filesystems ............................................................ Disk checking and recovery (fsck) ............................................. Check a Linux ext2 filesystem (e2fsck)....................................... Disk free space (df).................................................................. Disk usage (du)......................................................................... Disk partitioning concepts .......................................................... A Partitioned Disk ................................................................... Making and changing partitions .................................................. How many partitions? ............................................................... What size partitions? ................................................................. BIOS problems with LILO and partitions .................................... Disk partitioning tools ................................................................ 102 102 103 103 104 105 105 106 106 107 107 108 108 109 109 110 110 110 111
MSIT 3A Linux Internals 6.18 6.19 6.20 6.21 6.22 6.23 6.24 6.25 Using fdisk()............................................................................. The fdisk interface ................................................................... Interactive commands in fdisk..................................................... Making Linux filesystems (mke2fs) ............................................ Block devices ........................................................................... Character devices ..................................................................... Summary ................................................................................. Check Your Progress.................................................................
IX
111 112 112 113 113 114 114 115
Chapter 7 SYSTEM ADMINISTRATION 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 7.10 Introduction and objectives......................................................... The superuser account............................................................... User accounts /etc/passwd......................................................... Groups..................................................................................... Managing Linux users................................................................ User reference files................................................................... User modifications.................................................................... Examples of making changes to permissions................................ Some administration commands.................................................. Summary.................................................................................. Check Your Progress................................................................. 123 123 124 124 125 127 128 128 129 130 132 132
Chapter 8 EDITORS AND TOOLS 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 Introduction and objectives......................................................... Linux VI editor......................................................................... The emacs editor...................................................................... System and network configuration............................................... X Configuration........................................................................ Library and kernel dependency management................................ General Diagnostic.................................................................... To remotely use Xwindows from Ms Windows............................. Network application commands.................................................. Summary.................................................................................. Check Your Progress................................................................. 135 135 136 138 140 140 141 141 142 143 144 145
X
Chapter 9 ISTALLATION OF LINUX 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 9.12 9.13 9.14 9.15 9.16 9.17 9.18
Chapter 1 - Introduction
148 148 149 150 150 151 151 152 153 154 154 155 155 156 156 158 159 162 164 164
Introduction and objectives......................................................... Devices of installation................................................................ Partitioning hard disk................................................................. Partition sizes........................................................................... Mount points............................................................................. Mounting partitions at startup..................................................... The fstab file............................................................................ Know your hardware................................................................. Creating the Linux boot disk....................................................... Making a diskette under MS-DOS............................................... Making a diskette under a Linux-Like OS..................................... Beginning the installation of Linux .............................................. Installation options - class and method ........................................ Manual configurations................................................................ Package installations.................................................................. Standard linux partition filesystem types....................................... Network administration tools....................................................... Summary.................................................................................. Check Your Progress.................................................................
Chapter 1
Introduction
inux is an operating system that was first created at the University of Helsinki in Finland by a young student named Linus Torvalds. At this time the student was working on a UNIX system that was running on an expensive platform. Because of his low budget, and his need to work at home, he decided to create a copy of the UNIX system in order to run it on a less expensive platform, such as an IBM PC. He began his work in 1991 when he released version 0.02 and worked steadily until 1994 when version 1.0 of the Linux Kernel was released. There are no royalty or licensing fees for using Linux, and the source code can be modified to fit your needs. Because it comes with source code to the kernel, it is quite portable. Linux runs on more CPUs and platforms than any other computer operating system. Linux is a true multi-tasking operating system similar to its brother, UNIX. It uses sophisticated, stateof-the-art memory management to control all system processes. That means that if a program crashes you can kill it and continue working with confidence. Another benefit is that Linux is practically immunized against all kinds of viruses that we find in other operating systems.
Objectives
At the end of this unit, You would be able to know important features of Linux Unix system Architecture Significance of using a Linux System
Chapter 1 - Introduction
11
12
Linux command Line
Chapter 1 - Introduction
Exhibit login, logoff, Issue basic commands & switching to another account Linux directories and file system organization Know commands related to file retrievals
13
The Linux kernel uses no code from AT&T or any other proprietary source. Much of the software available for Linux is free. In fact, a large number of utilities in Linux are developed by the GNU project at the Free Software Foundation in Cambridge, Massachusetts. However, Linux enthusiasts, hackers, programmers, and recently even commercial companies from all over the world have contributed to the growing pool of Linux software. Linux supports (almost) all of the features of commercial versions of UNIX. In fact, some of the features found in Linux may not be available on other proprietary UNIX systems. GNU software support. Linux supports a wide range of free software written by the GNU Project, including utilities such as the GNU C and C++ compiler, gawk, groff, and so on. Many of the essential system utilities used by Linux are GNU software. Linux is compatible with the IEEE POSIX.1 standard. Linux has been developed with software portability in mind, thus supporting many important features of other UNIX standards. Virtual memory support. Linux utilizes all of your systems memory, without memory limits or segmentation through the use of a virtual memory manager. Built-in support for networking, multitasking, and other features. Youll see this touted as New Technology in systems such as Windows NT. In fact, UNIX (and now, Linux) has implemented this new technology for more than 15 years. Linux is cheaper to get than most commercially available UNIX systems and UNIX clones. If you have the patience and access to the Internet, the only price you pay for Linux is your time. Linux is freely available on the Internet.
Chapter 1 - Introduction
Multi-user. A user needs an account to use a computer. Each user must log in. Complete separation of different users files and configuration settings.
Small components. Each component should perform a single task. Multiple components can be combined and chained together for more complex tasks. An individual component can be substituted for another, without affecting other components.
15
Linux distributions. Kernel plus utilities plus other tools, packaged up for end users. Generally with installation program. Distributors include: Red Hat, Debian, SuSE, Mandrake.
Chapter 1 - Introduction
If in a text-only single-shell environment, exiting the shell should be sufficient. In a window environment, the window manager should have a log out command for this purpose. After logging out, a new login prompt should be displayed.
1.9 FILES
Data can be stored in a file. Each file has a filename. A label referring to a particular file.
17
Permitted characters include letters, digits, hyphens (-), underscores (_), and dots (.) Case-sensitive NewsCrew.mov is a different file from NewScrew.mov. The functions usually performed on a file are as follows: v Opening a file for processing. v Reading data from a file for processing. v Writing data to a file after processing. v Closing a file after all the necessary processing has been done.
18
Chapter 1 - Introduction
referred to as subdirectories). You can visualize the LINUX file structure as a bottom-up tree with the root at the top. Thus, the top-level directory is called the root directory and is denoted by a single / (forward slash). All the directories and files belong to the root directory. Below is a list of some common directories that are found in Linux and Unix systems, and what they are used for. / v This is the root directory, inside which all other directories reside v This is similar to the root directory of a drive in Windows (C:\), except that in Linux even different hard disks reside within this root. /bin v This stands for binary, and contains program (executable) files. This (and other bin directories) is where commands such as ls can be found. v In Windows, the c:\windows\commands holds some of command-line programs, but others are scattered in various other directories. /dev v This stands for devices. It contains a number of special pseudo-files that are used to access the physical hardware that make up, or are connected to, your computer. For example the parallel-port would be a file called lp0 in this directory, while the hard disk would be hda, and its first partition would be hda0. v Windows / DOS uses a similar method, however in Windows these are not in any particular directory. Devices have names like LPT1, COM1 or CON - any time you try to access a file with that name from any directory, you will get the parallel printer, serial port or console, respectively. /etc v This is where (almost) all system-wide configuration information is stored. Almost all configuration information is stored in text files, so you can go into this directory and have a look around with a text viewer if you like. Some of the files are quite cryptic though. v There is no equivalent in Windows, where configuration data can be stored anywhere, including the registry, INI files and other data files in various directories. /home v This is where users home directories are usually found. Thus, if you created a user called sandbox, there will be a directory with the same name in this directory, which will be that users home directory.
19
v The nearest equivalent in Windows is c:\windows\profiles, where some user-specific data is held, together with c:\My Documents, where user-created documents go. However other data can be written in many other directories. /lib v This is where the library files are found. Libraries are files containing reusable functions and routines for programs to use. v There is no equivalent in Windows / DOS. /mnt v This is where storage devices other than the hard disks are mounted. This directory usually contains subdirectories called cdrom, floppy, etc., which - when these devices are mounted - show the contents of the CD-ROM or floppy disk respectively. Your Windows drives may also be automatically mounted in this directory. v There is no equivalent in Windows / DOS. /opt v This is where optional components of the system are installed. Products such as KDE, Gnome and Oracle may be installed into this directory. v The nearest thing in Windows is the c:\Program Files directory. /tmp v This is a temporary directory. All files placed in here will automatically be deleted eventually. v The equivalent in Windows / DOS is c:\windows\temp. /usr v Contains a copy of most of the directories in the root. For example, there is a bin directory containing programs, a lib directory containing libraries, etc. Usually, core Linux files are contained in the root directories, while non-core files are in the /usr subdirectories. v There is no equivalent in Windows / DOS. /var v Stands for various. Among the files stored here are the system log files, spool files and other data files. v There is no equivalent in Windows / DOS.
Chapter 1 - Introduction
Note the greater-than sign (>) this is necessary to create the file. The text typed is written to a file with the specified name. Press Ctrl+D after a line-break to denote the end of the file. The next shell prompt is displayed.
21
Chapter 1 - Introduction
Once an unambiguous prefix has been typed, pressing Tab will automatically type the rest. For example, after typing this: $ rm sho pressing Tab key (key board) may turn it into this: $ rm shopping_list
This also works with command names. For example, da may be completed to date if no other commands start da.
1.19 SUMMARY
An operating system is an important part of a computer system. You can view a computer system as being built from three general components: the hardware, the operating system, and the applications. The hardware includes pieces such as a central processing unit (CPU), a keyboard, a hard drive, and a printer. You can think of these as the parts you are able to touch physically. Applications are why you use computers; they use the rest of the system to perform the desired task (for example, play a game, edit a memo, send electronic mail). The operating system is the component that on one side manages and controls the hardware and on the other manages the applications.
23
The operating system controls all the resources of the computer system and that control is given to the user. The user runs his applications to achieve the goal.
24
Chapter 1 - Introduction
c. Display the contents of this file. Minimise the typing needed to do this: Scroll back through the command history to the command you used to create the file. Change that command to display secret-of-the-universe instead of creating it. 4. After each of the following steps, use ls and cat to verify what has happened. a. Copy secret-of-the-universe to a new file called answer.txt. Use Tab to avoid typing the existing files name in full. b. Now copy hello.txt to answer.txt. Whats happened now? c. Delete the original file, hello.txt. d. Rename answer.txt to message. e. Try asking rm to delete a file called missing. What happens? f. Try copying secret-of-the-universe again, but dont specify a filename to which to copy. What happens now?
25
c) Operating system & hardware device d) All of the above 6. The standard way of mounting file systems onto the _________ directory. a) dev 7. b) mnt c) bin d) all of these
Linux supports ___________ file systems. a) Single b) NFS c) multiple d) all of these
8.
Linux support __________. a) multitasking only b) 32-bit c) Networking d) All of the above.
9.
10.
shell is a ___________. a) command interpreter b) operating system c) system call d) All of the above
26
IV. Essay Type Questions 1) What is Linux? Write brief features regarding Linux.
2) 3) 4) 5) 6) 7) 8) Explain the architecture of Unix. Explain the concept of filesystem. Elucidate the functions usually performed on a file. Explain how the directories are manipulated in Linux. Describe how the file systems are arranged? Give the types.
Chapter 1 - Introduction
Exhibit the commands for login, logoff & switching to another account. Enumerate the commands related to file retrivals.[ Ex: cat, rm, cp, mv ]
V. Further readings and other activities 1. The student shall get more information using man or info or any other help command for pwd, mkdir, cd, rmdir, sh, csh, ksh
Ex: man pwd OR info ls OR help cd OR apropos cp 2. 3. 4. Get new commands from the list given at the end of any man command information at the place see also. Using man intro, get the information about different kinds of commands present in your kind of linux system. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www.raomvp.bravepages.com/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. Title: Linux in a Nutshell Author: Jessica Perry Hekman and the staff of OReilly & Associates; ISBN 1-56592167-4; 1997. A complete reference for Linux. Title: Harley Hahns Student Guide to UNIX, second edition; McGraw- Hill; ISBN 007-025492-3; 1996. Not just for students, this is a complete and very readable guide to LINUX and networking.
27
VI. Solutions II. Choose the correct answer: II. 1. a 2. b 3. d 4. a III. Say True or False III 1. false 2. true
5. d 6. b 7. d 8. d 9. a 10. a
3. true
4. false
5. true
Chapter 2
Linux Commands
inux is a complete multitasking, multi-user operating system that behaves like the UNIX operating system in terms of kernel behavior and peripheral support. Linux has all the features of UNIX, plus several recent extensions that add new versatility to Linux. All source code for Linux and its utilities is freely available. The Linux kernel was originally developed for the Intel 80386 CPUs protected mode. The 80386 was designed with multitasking in mind (despite the fact that most of the Intel CPUs are used with singletasking DOS), and Linux makes good use of the advanced features built into the CPUs instruction set. Memory management is especially strong with the 80386 (compared to earlier CPUs). A floating-point emulation routine allows Linux to function on machines that do not have math coprocessors (such as the SX series of Intel CPUs). Linux allows shared executables so that if more than one copy of a particular application is loaded (either by one user running several identical tasks, or several users running the same task), all the tasks can share the same memory. This process, called copy-on-write pages, makes for much more efficient use of RAM. The Linux kernel also supports demand paging, which means that only sections of a program that are necessary are read into RAM. To further optimize memory usage, Linux uses a unified memory pool. This pool enables all free memory on the system to be used as disk cache, effectively speeding up access to frequently used programs and data. As memory usage increases, the amount of cache is automatically adjusted. To support large memory requirements when only small amounts of physical RAM are available, Linux supports swap space. Swap space enables pages of memory to be written to a reserved area of a
28
29
disk and treated as an extension of physical memory. By moving pages back and forth between the swap space and RAM, Linux can effectively behave as if it had more physical RAM than it does, albeit at the cost of some speed due to the hard drives slower access. Linux uses dynamically shared libraries extensively. Dynamically shared libraries use a common library section for many different applications, effectively reducing the size of each application. Linux does allow full library linking (called statically linked libraries) for portability to machines that may not have the dynamic libraries. To make Linux widely acceptable, it supports a number of different filesystems, including those compatible with DOS and OS/2. Linuxs own primary filesystem, called ext2fs, is designed for optimal use of the disk. Linux is ideally suited for application development and experimentation with new languages. Several different compilers, including C, C++, Fortran, Pascal, Modula-2, LISP, Ada, Basic, and Smalltalk, come with the distribution software. Many of the Linux compilers, tools, debuggers, and editors are from the Free Software Foundations GNU project. After completing this module you should be able to understand and utilize these features of the Linux commands: Basic Linux commands Help commands General commands File management commands Finding files Linux files and file Permission File names and permission characters Example to extract information from files Setting keystrokes Keys and terminal configuration
30
31
32
other info fileshave a look to the directory /usr/share/doc. To display manual page from a specific section, We may use something like: man 3 exit (this displays an info on the command exit from section 3 of the manual pages) or man -a exit (this displays man pages for exit from all sections). The man sections are: Section 1-User Commands, Section 2-System Calls, Section 3-Subroutines, Section 4-Devices, Section 5-File Formats, Section 6-Games, Section 7-Miscellaneous, Section 8-System Administration, Section 9, Section n-New. info topic Display the contents of the info on a particular command. info is a replacement for man pages so it contains the most recent updates to the system documentation. Use <Space> and <BkSpace> to move around or we may get confused. Press q to quit. A replacement for the somewhat confusing info browsing system might be pinfo - try if we like it any better. apropos topic Give me the list of the commands that have something to do with my topic. If does not work run $ updatedb as root. whatis topic Give me a short list of commands matching my topic. whatis is similar to apropos (see the command above)they both use the same database. But whatis searches keywords, while apropos also searches the descriptions of the keywords. help command Display brief info on a bash (shell) built-in command. Using help with no command prints the list of all bash built-in commands. The shortest list of bash built-in commands would probably include: alias, bg, cd, echo, exit, export, fg, help, history, jobs, kill, logout, pwd, set, source, ulimit, umask, unalias, unset. kdehelpcenter & (in X-terminal). Browse the whole system help using the graphical KDE help navigator. Normally, KDE help is invoked by pressing the appropriate icon on the KDE control panel. Use gnome-help-browser for the GNOME equivalent. (The older KDE versions used kdehelp& instead of kdehelpcenter&).
33
hostname Print the name of the local host (the machine on which We are working). Use netconf (as root) to change the name of the machine.
id username Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.
last Show listing of users last logged-in on the system. Really good idea to check it from time to time as a security measure on our system.
history | more Show the last (1000 or so) commands executed from the command line on the current account. The | more causes the display to stop after each screen. To see what another user was doing on the system, login as root and inspect his/her history. The history is kept in the file .bash_history in the user home directory.
uname -a (= Unix name with option all) Info on our (local) server. We can also use guname (in Xwindow terminal) to display the info more nicely.
free Memory info (in kilobytes). Shared memory is the memory that can be shared between processes (e.g., executable code is shared). Buffered and cashed memory is the part that keeps parts of recently accessed filesit can be shrunk if more memory is needed by processes.
echo $PATH Show the content of the environment variable PATH. This command can be used to show other environment variables as well. Use set to see the full environment.
34
ls or dir
List the contents of the current directory. The command dir is an alias to ls so these two commands do exactly the same thing. The file listing is normally color-coded: dark blue= directories, light grey = regular files, green = executable files, magenta = graphics files, red = compressed (zipped) files, light blue = symbolic links, yellow = device files, brown = FIFO (First-In First-Out named pipes). ls -al |more List the content of the current directory, all files (also those starting with a dot), and in a long form. Pipe the output through the more command, so that the display pauses after each screenful. The ls command has several very useful options. Some of these may have shortcuts (aliases) to avoid clumsy typing. Try ll (=long ls, an alias to ls -l). Another option We use quite often is ls-ad (list all the subdirectories in my current directory, but dont list their contents). cd directory Change directory. Using cd without the directory name will take us to our home directory. cd - will take us to our previous directory and is a convenient way to toggle between two directories. cd .. will take me one directory up (very useful). shutdown -h now (as root) Shut down the system to a halt. Mostly used for a remote shutdown. Use <Ctrl><Alt><Del> for a shutdown at the console (which can be done by any user). halt or reboot or init 6 (as root, three commands) Halt or reboot the machine. Used for remote shutdown, simpler to type than the previous command. Also great if the computer hangs (if we lose control over the keyboard)We can telnet to it from another machine on the network and remotely reboot it. We use <Ctrl><Alt><Del> for normal shutdown at the console of a local computer.
35
rmdir directory Remove an empty directory. rm -r files (recursive remove) Remove files, directories, and their subdirectories. Careful with this command as rootWe can easily remove all files on the system with such a command executed on the top of our directory tree, and there is no undelete in Linux (yet). But if We really wanted to do it (reconsider), here is how (as root): rm -rf /*
rm -rf files (recursive force remove). As above, but skip the prompt for confirmation, if one is set on our system. Careful with this command particularly as rootsee the command above.
cat filename | more View the content of a text file called filename, one page a time. The | is the pipe symbol (on many American keyboards it shares the key with \). more makes the output stop after each screenful. For long files, it is sometimes convenient to use the commands head and tail that display just the beginning and the end of the file, or less that enables scrolling up and down. If we happened to use cat a binary file and our terminal displays funny characters afterwards, we can restore it with the command reset.
cat filename | less, less filename (two commands, use either) Scroll a content of a text file. Press q when done. less is roughly an equivalent to more , the command we know from DOS, but often less is more convenient than more because it lets me scroll both up and down.
head filename Print first 10 lines of the (long) text file. tail filename Print last 10 lines of a long or growing text file. Use tail -f filename for tail to follow the file as it growsreally handy for continuing inspection of log files.
ispell filename Spell check an ASCII text file. AbiWord, WordPerfect, StarOffice and other word processors come with as-we-type spellchecking, so we really dont have to worry about the simple ispell unless we need it.
touch filename Change the date/time stamp of the file filename to the current time. Create an empty file if the file does not exist. You can change the stamp to any date using touch -t 200201311759.30 (year 2002 January day 31 time 17:59:30).
36
There are three date/time values associated with every file on an ext2 filesystem: the time of last access to the file (atime) the time of last modification to the file (mtime) the time of last change to the files inode (ctime). Touch will change the first two to the value specified, and the last one always to the current system time. They can all be read using the stat command. stat filename Print general info about a file (the contents of the so-called inode). strings filename | more Display the strings contained in the binary file called filename. strings could, for example, be a useful first step to a close examination of an unknown executable. od (=octal dump). Display contents as octal numbers. This can be useful when the output contains non-printable characters. For example, a filename may contain non-printable characters and be a real pain. This can also be handy to view binary files. Examples: dir | od -c | more sort -f filename Arrange the lines in filename according to the ascii order. The option -f tells sort to ignore the upper and lower character case. uniq (=unique) Eliminate duplicate lines in sorted input. Example: sort myfile | uniq fold -w 30 -s my_file.txt > new_file.txt Wrap the lines in the text file my_file.txt so that there is 30 characters per line. Break the lines on spaces. Output goes to new_file.txt. rev filename > filename1 Print the file filename, each line in reversed order. In the example above, the output is directed to the file filename1. paste file1 file2 > file3 Merge two or more text files on lines using <Tab> as delimiter (use option d= to specify our own delimiter(s).
37
join file1 file2 > file3 Join lines of two files on a common field. join parallels the database operation join tables, but works on text tables. The default is to join on the first field of the first table, and the default delimiter is white space.
38
There are a total of 10 characters in this example for all Linux / Unix files. The first character indicates the type of file, and the next three indicate read, write, and execute permission for each of the three user types, user, group and other. Since there are three types of permission for three users, there are a total of nine permission bits. The table below shows the syntax: v Character 1 is the type of file: - is ordinary, d is directory, l is link. v Characters 2-4 show owner permissions. Character 2 indicates read permission, character 3 indicates write permission, and character 4 indicates execute permission. v Characters 5-7 show group permissions. Character 5=read, 6=write, 7=execute v Characters 8-10 show permissions for all other users. Character 8=read, 9=write, 10=execute
There are 5 possible characters in the permission fields. They are: r = read - This is only found in the read field. w = write - This is only found in the write field. x = execute - This is only found in the execute field. s = setuid - This is only found in the execute field. If there is a - in a particular location, there is no permission. This may be found in any field of read, write, or execute.
39
4 1 1
The fields are as follows: 1. Type field: The first character in the field indicates a file type of one of the following: d = directory l = symbolic link s = socket p = named pipe - = regular file c= character (un buffered) device file special b=block (buffered) device file special
2. 3. 4. 5. 6. 7. 8.
Permissions are explained above. Links: The number of directory entries that refer to the file. In our example, there are four. The files owner in our example is George. The group the file belongs to. In our example, the group is team1. The size of the file in bytes The last modification date. If the file is recent, the date and time is shown. If the file is not in the current year, the year is shown rather than time. The name of the file.
The stty command - Used to set up keystrokes on terminals [try $ stty a]. The command <stty erase ^H> will bind the Backspace key(^H) to the erase function. Characters that are specified: v eof - End of file v eol - End of line v eol2 - Alternate character for ending a line v erase - Erase the last character typed v intr - The specified character will send an interrupt signal v kill - Erase the current line. v quit - Sends a quit signal. v start - Restart output after having stopped it. v stop - Stops the output. v susp - Sends a terminal stop signal v switch - Switch to a different shell layer v werase - erase the last word typed. setterm foreground white background blue setterm store Sets white foreground, and blue background Stores the present terminal values as default
41
v <CRTL><ALT>F7 - Toggle to the first X terminal, if one is running. v <CRTL><ALT>F1 - Toggle to the first text terminal from an X session. v CTRL D - End of file, exits the shell v CTRL W - Delete a word backwards v CTRL / - Quit, weaker than CTRL C but does a core dump. v CTRL S - Stop scrolling, may use scroll lock for this function. v CTRL Q - Resume scrolling
2.11 SUMMARY
A UNIX command is a series of characters that we type. These characters consist of words that are separated by whitespace. Whitespace is the result of typing one or more Space or Tab keys. The first word is the name of the command. The rest of the words are called the commands arguments. The arguments give the command information that it might need, or specify varying behavior of the command. You can use command options to fine-tune the actions of a Linux command. Quite often, a Linux command will do almost, but not quite what you want it to do. Instead of making you learn a second command, Linux lets you modify the basic, or default, actions of the command by using options. Most Linux commands are very flexible. When you enter a Linux command, there are several ways to tailor the basic command to your specific needs. We will look at the two main ways used to modify the effect of a command: v Specifying or redirecting a commands input and output v Using command options Standard LINUX commands makes shell scripts more versatile. The power of scripts comes from coupling system commands and shell directives with simple programming constructs.
42
Go to home directory. Copy distant file to working directory. Create new directory. List working directory. Move file to new directory. Change working directory. Copy file to working directory. Print the file. List filenames with wildcard. Remove files. Go up to parent directory. Remove directory. Verify that directory was removed. Enter cd
Enter cp /etc/passwd myfile Enter mkdir temp Enter ls F Enter mv myfile temp Enter cd temp Enter cp myfile myfile.two Enter the printer command and the filename Enter ls -l myfile* Enter rm myfile* Enter cd .. Enter rmdir temp Enter ls F
43
3)
touch command is used for ____________. a) Updating access/modification times of a file to current system time b) Creating a new file c) Both a) & b) d) None of the above
4)
Diff reports ____________________ a) Differences between two files b) At what point the files differ c) Removes duplicate lines d) None of the above.
5)
egrep an acronym for __________________________. a) evaluation global regular expression print b) extensible global regular expression print c) extended global regular expression print d) none of the above.
6)
traceroute works within ______ a) LAN b) WAN c) Over the internet d) All of the above
7)
If finger is used without an argument ___________________________ a) it gives information concerning users currently logged in b) it gives information about a particular user on a network c) it gives information about all users d) none of the above
44
8) Protocol used for connecting to a remote host _______. a) ftp b) telnet c) tcp/ip d) none of the above 9) df command is used for__________ purpose. a) Communication b) System & administrative c) Networking d) File & archiving 10) Command used for shutting down the system ______ a) halt b) exit c) quit d) logout 11) The following are Network related Commands _______ a) Wall b) ftp c) host d) none of the above
45
tr a-z \* < filename changes all the lowercase letters in filename to asterisks True/False exec shell builtin replaces the present process with a specified command. kill command resumes a process. True/False True/False
IV. Essay Type Questions 1. Write a short notes on the following with relevant options.
a. cat & tac b. chmod c. touch d. sort e. grep 2. 3. 4. 5. Explain any three help, file and text Processing Commands. Write in detial about tar command with the relvant options. Give the differentiation between locate, find & slocate. Give a short note on the following communication commands. a. cat b. rm 6. List the differences between the following. a. mv & cp b. tac & rev c. expr & let d. cmp & diff
46
V. Further readings and other activities 1. Get more information using man or info or any help command for find, date, uniq, stty, diff, cmp, ls
EX: 1. $ man du 2. $ apropos bash
Check the amount of space used, amount of space free for different drives and different directories. 2. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www.raomvp.bravepages.com/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. Title: principles of unix programming Auihors: Sumitabha Das Work and expertise all the commands given in the chapter with different options and by the virtue of which know, which command is to be used for different situations of jobs.
VI. Solutions II. Choose the correct answer: 1.b 2.a 3.c 4.a III. Say True or False 1.True 2.True
5.c 6.d 7.b 8.b 9.b 10.a 11.d
3.True
4.True
5.True
6.True
7.False
Chapter 3
Processes
Objectives
After completing this module you should be able to understand and utilize these features of the Linux processes: Looking at processes Process IDs Analysis of active processes Different output formats of ps
47
48
Killing a process Processes creation mechanisms Using system, system calls - fork, exec Calling fork, using the exec Family Using fork and exec Together Process scheduling Signals and Linux daemons Most useful daemons Zombie process and threads Differentiating processes and threads
Chapter 3 - Processes
49
{ printf (The process ID is %d\n, (int) getpid ()); printf (The parent process ID is %d\n, (int) getppid ()); return 0; } Observe that if we invoke this program several times, a different process ID is reported because each invocation is in a new process. However, if we invoke it every time from the same shell, the parent process ID (that is, the process ID of the shell process) is the same.
50
Chapter 3 - Processes want in the output as a comma-separated list. For example, ps -o pid,user,start_time,command displays the process ID, the name of the user owning the process, the wall clock time at which the process started, and the command running in the process. See the man page for ps for the full list of field codes. We can use the -f (full listing), -l (long listing), or -j (jobs listing) options instead to get three different preset listing formats. Here are the first few line and last few lines of output from this command on the system. We may see different output, depending on whats running on our system. $ ps -e -o pid,ppid,command PID 1 2 3 ... 21725 21727 21728 PPID 0 1 1 21693 21725 21727 COMMAND init [5] [kflushd] [kupdate] xterm bash ps -e -o pid,ppid,command
Note that the parent process ID of the ps command, 21727, is the process ID of bash, the shell from which we invoked ps. The parent process ID of bash is in turn 21725, the process ID of the xterm program in which the shell is running. Using ps provides us a snapshot of the systems active processes. The following are the fields from the output of the ps command that are important in terms of performance tuning: Description Flags that indicate the processs current state and are calculated by adding each of the hexadecimal values: Process has terminated System process, always in memory Process is being traced by its parent Process is being traced by parent, and is stopped Process cannot be awakened by a signal Process is in memory and locked, pending an event Process cannot be swapped The current state of the process, as indicated by one of the following letters:
Field F 00 01 02 04 08 10 20 S
51
O S R I Z T X
Process is currently running on the processor Process is sleeping, waiting for an I/O event (including terminal I/O) to complete Process is ready to run Process is idle Process is a zombie process (it has terminated, and the parent is not waiting but is still in the process table) Process is stopped because of parent tracing it Process is waiting for more memory
killall HUP myprint Restarts any process with the name myprint. kill TERM myprint Terminates any process with the name myprint.
Chapter 3 - Processes
Two common techniques are used for creating a new process. The first is relatively simple but should be used sparingly because it is inefficient and has considerably security risks. The second technique is more complex but provides greater flexibility, speed, and security.
53
54
{ pid_t child_pid; printf (the main program process ID is %d\n, (int) getpid ()); child_pid = fork (); if (child_pid != 0) { printf (this is the parent process, with id %d\n, (int) getpid ()); printf (the childs process ID is %d\n, (int) child_pid); } else printf (this is the child process, with id %d\n, (int) getpid ()); return 0; }
Chapter 3 - Processes
55
Because exec replaces the calling program with another one, it never returns unless an error occurs.
56
Chapter 3 - Processes
Note that only a process with root privilege can run a process with a negative niceness value or reduce the niceness value of a running process. This means that we may specify negative values to the nice and renice commands only when logged in as root, and only a process running as root can pass a negative value to the nice function. This prevents ordinary users from grabbing execution priority away from others using the system.
3.13 SIGNALS
Signals are mechanisms for communicating with and manipulating processes in Linux. The topic of signals is a large one; here we discuss some of the most important signals and techniques that are used for controlling processes. A signal is a special message sent to a process. Signals are asynchronous; when a process receives a signal, it processes the signal immediately, without finishing the current function or even the current line of code. There are several dozen different signals, each with a different meaning. Each signal type is specified by its signal number, but in programs, we usually refer to a signal by its name. In Linux, these are defined in /usr/include/bits/signum.h. (We shouldnt include this header file directly in our programs; instead, use <signal.h>.) When a process receives a signal, it may do one of several things, depending on the signals disposition (address space). For each signal, there is a default disposition, which determines what happens to the process if the program does not specify some other behavior. For most signal types, a program may specify some other behavioreither to ignore the signal or to call a special signal-handler function to respond to the signal. If a signal handler is used, the currently executing program is paused, the signal handler is executed from other address space. When the signal handler returns, the program resumes. The Linux system sends signals to processes in response to specific conditions. For instance, SIGBUS (bus error), SIGSEGV (segmentation violation), and SIGFPE (floating point exception) may be sent to a process that attempts to perform an illegal operation. The default disposition [action] for these signals it to terminate the process and produce a core file. A process may also send a signal to another process. One common use of this mechanism is to end another process by sending it a SIGTERM or SIGKILL signal. Another common use is to send a command to a running program. Two userdefined signals are reserved for this purpose: SIGUSR1 and SIGUSR2. The SIGHUP signal is sometimes used for this purpose as well, commonly to wake up an idle program or cause a program to reread its configuration files.
57
The sigaction function can be used to set a signal disposition. The first parameter is the signal number. The next two parameters are pointers to sigaction structures; the first of these contains the desired disposition for that signal number, while the second receives the previous disposition. The most important field in the first or second sigaction structure is sa_handler. It can take one of three values: SIG_DFL, which specifies the default disposition for the signal. SIG_IGN, which specifies that the signal should be ignored. A pointer to a signal-handler function. The function should take one parameter, the signal number, and return void. Because signals are asynchronous, the main program may be in a very fragile state when a signal is processed and thus while a signal handler function executes. Therefore, we should avoid performing any I/O operations or calling most library and system functions from signal handlers. A signal handler should perform the minimum work necessary to respond to the signal, and then return control to the main program (or terminate the program). In most cases, this consists simply of recording the fact that a signal occurred. The main program then checks periodically whether a signal has occurred and reacts accordingly. It is possible for a signal handler to be interrupted by the delivery of another signal. While this may sound like a rare occurrence, if it does occur, it will be very difficult to diagnose and debug the problem. Therefore, we should be very careful about what our program does in a signal handler. Even assigning a value to a global variable can be dangerous because the assignment may actually be carried out in two or more machine instructions, and a second signal may occur between them, leaving the variable in a corrupted state. If we use a global variable to flag a signal from a signal-handler function, it should be of the special type sig_atomic_t. Linux guarantees that assignments to variables of this type are performed in a single instruction and therefore cannot be interrupted midway. In Linux, sig_atomic_t is an ordinary int; in fact, assignments to integer types the size of int or smaller, or to pointers, are atomic. If we want to write a program thats portable to any standard UNIX system, though, use sig_atomic_t for these global variables.
58
Chapter 3 - Processes
Our Linux system is likely set to run quite a number of daemons. Most of them can be (dis)selected by running the program ntsysv (RedHat) as root and checking the appropriate box. The short description of each daemon is available under netsysv by pressing <F1>. If the daemon we need is not listed in ntsysv, we need to insert our RedHat installation CD and install the appropriate package. The alternative to ntsysv may be tksysv (type as root, in X terminal), Which is perhaps more flexible, but way more complicated (it lets us set up the list of daemons to run in each runlevel). Another, simpler and even more powerful flexible difficult to use tool is /sbin/ chkconfig.
59
This daemon can automatically load and unload other daemons (ftpd, telnetd, etc.), thereby economizing on system resources. Newer systems use xinetd instead. v kudzu - detects and configures new or changed hardware during boot. v linuxconf - the linuxconf configuration tool. The automated part is run if we want linuxconf to perform various tasks at boottime to maintain the system configuration. v lpd - printing daemon. v named - the Internet Domain Name Server (DNS) daemon. v netfsd - network filesystem mounter. Used for mounting nfs, smb and ncp shares on boot. v networkd -activates all network interfaces at boot time by calling scripts in /etc/sysconfig network-scripts. v nfsd - used for exporting nfs shares when requested by remote systems. v portmap - needed for Remote Procedure Calls. Most likely, we need it for running network. v routed - daemon that manages routing tables. v rstatd - kernel statistics server. v rusersd, rwalld - identification of users and wall messaging services for remote users. v rwhod - server which maintains the database used by the rwho(1) and ruptime(1) programs. Its operation depends on the ability to broadcast messages on a network. v sendmaild - mail transfer agent. This is the agent that comes with Red Hat. v smbd - the SAMBA (or smb) daemon, a network connectivity services to MS Windows computers on our network (hard drive sharing, printers, etc). v squid - An http proxy with caching. Proxies relay requests from clients to the outside world, and return the results. We would use this particular proxy if we wanted to use our linux computer as a gateway to the Internet for other computer on our network. Another (and probably safer at home) way to do it, is to set up masquarading. v syslogd - manages system activity logging. The configuration file is /etc/syslog.conf. v smtpd - Simple Mail Transfer Protocol, designed for the exchange of electronic mail messages. Several daemons that support SMTP are available, including sendmail, smtpd, rsmtpd, qmail, zmail, etc. v ypbind - NIS binder. Needed if computer is part of Network Information Service domain.
Chapter 3 - Processes
If a child process terminates while its parent is calling a wait function, the child process vanishes and its termination status is passed to its parent via the wait call. But what happens when a child process terminates and the parent is not calling wait? Does it simply vanish? No, because then information about its terminationsuch as whether it exited normally and, if so, what its exit status iswould be lost. Instead, when a child process terminates, is becomes a zombie process. A zombie process is a process that has terminated but has not been cleaned up yet. It is the responsibility of the parent process to clean up its zombie children. The wait functions do this, too, so its not necessary to track whether our child process is still executing before waiting for it. Suppose, for instance, that a program forks a child process, performs some other computations, and then calls wait. If the child process has not terminated at that point, the parent process will block in the wait call until the child process finishes. If the child process finishes before the parent process calls wait, the child process becomes a zombie. When the parent process calls wait, the zombie childs termination status is extracted, the child process is deleted, and the wait call returns immediately. Orphan process is a parent less child. What happens if the parent does not clean up its children? They stay around in the system, as zombie processes. The program in Listing below forks a child process, which terminates immediately and then goes to sleep for a minute, without ever cleaning up the child process. Listing (zombie.c) Making a Zombie Process #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main () { pid_t child_pid; /* Create a child process. */ child_pid = fork (); if (child_pid > 0) { /* This is the parent process. Sleep for a minute. */ sleep (60);
v v
v v
61
} else { /* This is the child process. Exit immediately. */ exit (0); } return 0; } Try compiling this file to an executable named make-zombie. Run it, and while its still running, list the processes on the system by invoking the following command in another window: $ ps -e -o pid,ppid,stat,cmd This lists the process ID, parent process ID, process status, and process command line. Observe that, in addition to the parent make-zombie process, there is another make-zombie process listed. Its the child process; note that its parent process ID is the process ID of the main make-zombie process. The child process is marked as <defunct>, and its status code is Z, for zombie. What happens when the main make-zombie program ends when the parent process exits, without ever calling wait? Does the zombie process stay around? Notry running ps again, and note that both of the make-zombie processes are gone. When a program exits, its children are inherited by a special process, the init program, which always runs with process ID of 1 (its the first process started when Linux boots).The init process automatically cleans up any zombie child processes that it inherits.
3.17 THREADS
Threads, like processes, are a mechanism to allow a program to do more than one thing at a time. As with processes, threads appear to run concurrently; the Linux kernel schedules them asynchronously, interrupting each thread from time to time to give others a chance to execute. Conceptually, a thread exists within a process. Threads are a finer-grained unit of execution than processes. When we invoke a program, Linux creates a new process and in that process creates a single thread, which runs the program sequentially. That thread can create additional threads; all these threads run the same program in the same process, but each thread may be executing a different part of the program at any given time.
62
Chapter 3 - Processes
Weve seen how a program can fork a child process. The child process is initially running its parents program, with its parents virtual memory, file descriptors, and so on copied. The child process can modify its memory, close file descriptors, and the like without affecting its parent, and vice versa. When a program creates another thread, though, nothing is copied. The creating and the created thread share the same memory space, file descriptors, and other system resources as the original. If one thread changes the value of a variable, for instance, the other thread subsequently will see the modified value. Similarly, if one thread closes a file descriptor, other threads may not read from or write to that file descriptor. Because a process and all its threads can be executing only one program at a time, if any thread inside a process calls one of the exec functions, all the other threads are ended (the new program may, of course, create new threads).
63
3.19 SUMMARY
Process defined as: A process is program (command given by user) to perform specific Job. In Linux when you start process, it gives a number to process (called PID or process-id), PID starts from 0 to 65535. Process & PID defined as: An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process. TOOLS FOR WORKING WITH PROCESSES v accton - Turns process accounting on and off. Uses the file /var/log/pacct. To turn it on type accton /var/log/pacct. Use the command with no arguments to turn it off. v kill - Kill a process by number v killall - Send a signal to a process by name v lastcomm (1) - Display information about previous commands in reverse order. Works only if process accounting is on. v nice - Set process priority of new processes. v ps(1) - Used to report the status of one or more processes. v pstree(1) - Display the tree of running processes. v renice(8) - Can be used to change the process priority of a currently running process. v sa(8) - Generates a summary of information about users processes that are stored in the / var/log/pacct file. v skill - Report process status. v snice - Report process status. v top - Displays the processes that are using the most CPU resources.
Chapter 3 - Processes
I. Exercises v You are working on your Linux workstation (like sending mails, typing letter), while doing this work you have started to play MP3 files on your workstation. Regarding this situation, answer the following question:
1) Is it example of Multitasking? 2) How you will find out the both running process (MP3 Playing & Letter typing)? 3) Currently only two Process are running in your Linux / PC environment, Is it True or False?, And how you will verify this? 4) You dont want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action: 1. Turn off Speakers 2. Turn off Computer / Shutdown Linux Os 3. Kill the MP3 playing process 4. None of the above
65
3.
To run a command in the background, add the & character ________of the command line. a. At the end b. At the beginning c. In the middle d. Any where
4.
We can kill a process by typing ______ and the PID number right afterwards. a. pid b. kill c. signal d. none of the above
5.
Common techniques used for creating a new process is using ______. a. system(). b. fork() c. fork(), exec() and wait() d. All of the above
6.
________ command is used to set priority for the process. a. more b. less c. nice d. all of the above.
7.
_____ are long running processes, having high [long] life. a. Daemons b. Threads c. Zombie d. Orphan
66
III. Say True or False 1. Each signal type is specified by its signal number.
2. 3. 4. 5. Threads, like processes, are a mechanism to allow a program to do more than one thing at a time
Chapter 3 - Processes
Process IDs are 16-bit numbers that are assigned sequentially by Linux as new processes are created. True / False A signal is program (command given by user) to perform specific Job. pstree() - Display the tree of running processes. True / False
IV. Essay type questions 1. What is meant by process ? Explain its states briefly.
2. 3. 4. 5. 6. 7. 8. 9. Explain how a process can be created. What is meant by background processing ? illustrate with example. Differentiate a process and thread in detail. What is a daemon? Describe the most popular daemons with their functions. Describe the output formats of ps command with respect to performance analysis. Elucidate the techniques of creating the processes with examples. Write a note on zombie, thread, daemon and Orphan. Explain the different types of Linux processes.
V. Further readings and other activities 1. Get more information using man or info or any help command for init, getty, daemon, telnetd, SIGQUIT, SIGABRT, ps, top, nice.
2. Work on processes by executing small programs.: Following table lists most commonly used command(s) with process:
67
Use this Command ps kill {PID} killall {Process-name} ps ag kill 0 Examples* $ ps $ kill 1012 $ killall httpd $ ps ag $ kill 0
For this purpose To see currently running process To stop any process by PID i.e. to kill process To stop processes by name i.e. to kill process To get information about all running process To stop all process except your shell For background processing (With &, use to put particular command and program in background) To display the owner of the processes along with the processes To see if a particular process is running or not. For this purpose you have to use ps command in combination with the grep command To see currently running processes and other information like memory and CPU usage with real time updates. To display a tree of processes
linux-command &
$ ls / -R | wc -l &
ps aux
$ ps aux For e.g. you want to see server process is runningor not then give command $ ps ax | grep httpd $ top
top
pstree
* To run some of this command you need to be root or equivalent user. 3. Books for Reference Title: Linux internals
68
Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www. geocities.com/raomvp/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises.
Chapter 3 - Processes
Title: Linux in a Nutshell - a good overview of all the most common Linux commands, process including a comprehensive section on the bash shell.
VI. Solutions I. Exercises 1) Is it example of Multitasking? Ans.: Yes, since we are running two process simultaneously.
2) 3) How you will find out the both running process (MP3 Playing & Letter typing)? Ans.: Try $ ps -aux or $ ps -ax | grep process-you-want-to-search Currently only two Process are running in your Linux/PC environment, Is it True or False?, And how you will verify this? Ans.: No its not true, when you start Linux Os, various process start in background for different purpose. To verify this simply use top or ps -aux command. You dont want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action: 1. Turn off Speakers 2. Turn off Computer / Shutdown Linux Os 3. Kill the MP3 playing process 4. None of the above Ans.: Use action no. 3 i.e. kill the MP3 process. Tip: First find the PID of MP3 playing process by issuing command: $ ps -ax | grep mp3-process-name Then in the first column you will get PID of process. Kill this PID to end the process as: $ kill PID Or you can try killall command to kill process by name as follows: $ killall mp3-process-name
4)
69
II. Choose appropriate answer 1.d 2.b 3.a 4.b III. Say True or False 1. True 2. True 3. True
5.d
6.c
7.a
4. False
5. True
Chapter 4
Shell Programming
shell script is a series of shell commands, similar to the ones given above, contained in a file, which can be given to the bash program to be executed in sequence. Technically, it is a program with bash as the language.
There are several shells available on the Linux system (if we installed them): bash (Bourne Again shell), sh (Bourne shell, standard on many UNIX systems), csh (C shell, with a syntax akin to the c programming language, available on most UNIX systems), pdksh (public domain Korn shell), tcsh (tiny C shell, often used on small systems), sash (stand-alone shell, could be used when libraries are not available), ash, zsh, and perhaps a couple more.
Objectives
At the end of this unit, You would be able to Understand the analogy of shell programming Creation of a shell script Meta characters Positional Parameters and Shell Variables Built-in shell commands and variables Iteration, control and if statements Shell operators
70
71
We can use any text editor to create the shell script - simply choose one, that we are comfortable with. If we are using KDE, We can use the Advanced Editor (kate or kwrite), or kedit. Do not use a word processing program - these are not text editors, and insert additional formatting information into the text. If, however, we know how to use our word processor to save plain-text file, go ahead and use it. Start with a new file firstshellscript.sh, and type the following lines. Example: $ vi firstshellscipt.sh #!/bin/bash echo I am about to list the files present in home directory # here is the actual listing: ls $HOME # HOME = /rao/laptop echo Done!
The first line has a special meaning. It tells the current shell which program should be used to interpret this file. Here, we have given the filename of the bash program. This is so that, if this script is invoked from within a different shell, or from a file-management program such as Konqueror and Nautilus, it will still know that this script requires the bash shell to run it. The second line is our first command. We use the echo command to display a simple line of information. The third line is a comment. Bash simply ignores it, but it can be useful to a person reading the program in the future to understand what the code is trying to do. While comments are not very useful in such a short, simple script, they are vital in longer and more cryptic ones. This is followed by two more commands - the ls command which takes the directory name as a parameter, and finally another echo to display our final declaration of triumph! When we save this file, it shows up as an ordinary file, which cannot be executed. In order to run it, we must make it executable. To do this, we use the chmod command. In the following example, we have used firstshellscript.sh as the script name - we should change that to whichever name we used. $ chmod u+x firstshellscript.sh
72
Thats it! We can now execute the new script. To do this, enter the following command, again replacing firstshellscript.sh with the name we used if different. rao@laptop $ ./firstshellscript.sh I am about to list the home directory KDesktop firstshellscript.sh public_html snapshot1.png usr-listing.txt Done!
Note the ./ at the beginning of the file - this is actually a directory name (a single period means the current directory). We can avoid this by placing the new script, and any others we create, in a directory within the PATH environment variable. Then we can enter the command from wherever we are.
The following table provides a list of characters or combination characters called as meta characters [wildcards]. They have special predefined meaning to the shell. By using one or more special symbols, the shell will find those files, which match a pattern, and place them on the command line instead of the pattern itself. v Meaning of some special characters. Character $ | # & ? * $# $* $? $$ Meaning Indicates the beginning of a shell variable name. For example, $var will look for a shell variable named var. Pipes standard output to next command. Start a comment. Executes a process in the background. Matches one character. Matches none or more characters. Number of arguments passed to a shell script. Arguments passed to a shell script. Returns code from the previous executed command. Process identification number.
73
> <
(backquote) Command substitution. >> [] . filename : Output redirection operator (to append to a file). Lists a range of characters. [a-z] means all characters a through z. [a,z] means characters a or z. Executes the file filename Directory name separator in the path.
74
75
limit login logout newgrp nice nohup notify onintr popd pushd rehash repeat set setenv shift source stop suspend switch time umask unalias unhash unlimit unset unsetenv wait while %job @
Respecifies maximum resource limits Invokes the system logon procedure Exits from a logon shell Changes our Group ID Controls background process dispatch priority Prevents termination on logout Requests notification of background job status changes Processes an interrupt within a shell script Returns to a previous directory Changes directory with pushdown stack Rehashes the directory search path Executes a command repeatedly Displays or changes a shell variable Sets environment variable Shifts parameters Interprets a script in the current shell Stops a background job Stops the current shell Specifies conditional execution Times a command Displays or sets the process file-creation mask Deletes a command alias Disables use of the hash table Cancels a previous limit command Deletes shell variables Deletes environment variables Waits for background jobs to finish Specifies a looping control Specifies foreground execution Specifies expression evaluation
76
v Built-in shell variables Variable $# $? $0 $* $@ Use
Stores the number of command-line arguments that were passed to the shell program. Stores the exit value of the last command that was executed. Stores the first word of the entered command (the name of the shell program). Stores all the arguments that were entered on the command line ($1 $2 ...). Stores all the arguments that were entered on the command line, individually quoted ($1 $2 ...).
77
3 A comment line. 4 This line extracts the name of the file from its full path pointed to by the variable $i and puts it in the variable $filename. The method used here is called parameter expansion and is documented in the bash man page. For more information on parameter expansion read the Linux Programmers Guide. 5 This line sends a statement to the standard output, telling what file is being copied. 6 This line performs the copy command using the -p option to preserve file attributes. Note: Much ability to perform script programming is couched in the ability to know and use the various commands, programs and tools available in Linux rather than a strict understanding of syntax. This is obvious to anyone who reads the system startup script files in /etc/rc.d and associated directories. 7 This line ends the if statement. 8 This line ends the for statement. 1. for i in /mnt/floppy/*; do 2. if [ -f $i ]; then 3. # if the file is there 4. filename=${i#/mnt/floppy/} 5. echo copying $i to /etc/$filename 6. cp -p $i /etc/$filename 7. fi 8. done until - Cycles through a loop until some condition is met. The syntax for the command is shown below: until [ expression ] do statements done while - Cycles through a loop while some condition is met. The below example will cycle through a loop forever: while [ 1 ] do statement(s) done
Meaning
But in Shell For test statement with if command For [ expr ] statement with if command if [ 5 -eq 6 ] if [ 5 -ne 6 ] if [ 5 -lt 6 ] if [ 5 -le 6 ] if [ 5 -gt 6 ] if [ 5 -ge 6 ]
is equal to is not equal to is less than is less than or equal to is greater than is greater than or equal to
Meaning string1 is equal to string2 string1 is NOT equal to string2 string1 is NOT NULL or not defined string1 is NOT NULL and does exist string1 is NULL and does exist
79
Meaning Non empty file Is File exist or normal file and not a directory Is Directory exist and not a file Is writeable file Is read -only file Is file is executable
80
THE TEST COMMANDS INTEGER OPERATORS : Operator int1 eq int2 int1 ge int2 int1 gt int2 int1 le int2 int1 lt int2 int1 ne int2 Meaning Returns True if int1 is equal to int2. Returns True if int1 is greater than or equal to int2. Returns True if int1 is greater than int2. Returns True if int1 is less than or equal to int2. Returns True if int1 is less than int2. Returns True if int1 is not equal to int2.
The string operators are used to evaluate string expressions. Table lists the string operators that are supported by the three shell programming languages.
THE TEST COMMANDS STRING OPERATORS: Operator str1 = str2 str1 != str2 str -n str -z str Meaning Returns True if str1 is identical to str2. Returns True if str1 is not identical to str2. Returns True if str is not null. Returns True if the length of str is greater than zero. Returns True if the length of str is equal to zero. The test commands file operators are used to perform functions such as checking to see if a file exists and checking to see what kind of file is passed as an argument to the test command. Table below lists the test commands file operators.
The test commands file operators: Operator -d filename -f filename -r filename -s filename -w filename -x filename Meaning Returns True if file, filename is a directory. Returns True if file, filename is an ordinary file. Returns True if file, filename can be read by the process. Returns True if file, filename has a nonzero length. Returns True if file, filename can be written by the process. Returns True if file, filename is executable.
81
The test commands logical operators are used to combine two or more of the integer, string, or file operators or to negate a single integer, string, or file operator. Table below lists the test commands logical operators.
THE TEST COMMANDS LOGICAL OPERATORS: Command ! expr expr1 -a expr2 expr1 -o expr2 Meaning Returns True if expr is not true. Returns True if expr1 and expr2 are true. Returns True if expr1 or expr2 is true.
82
echo exiting... DONE=yes ;; ls) ls -al |more ;; *) echo $ENTRY is an unrecognized command. ;; esac done
83
PATH: This variable, usually set in our .profile, contains a list of directories that are searched for executables. If an executable, Which is any utility, program, or shell program, is not in the PATH variable, it can only be executed by giving the full pathname of the executable file. The directories are searched in the order in which they appear in the PATH variable. PS1: The value of the interactive shell prompt. The default value in the Bourne Shell is $. [set $ ps1= [pwd] > and then invoke $ echo $PS1 ] PS2: The value of the secondary shell prompt. The default value is >. TERM: This variable is not automatically created on all UNIX systems but is used by so many programs that it is considered a standard environment variable. TERM usually contains the type of terminal that we are using, such as ansi or vt100. SHELL: The current shell program that is being executed. Default is /bin/bash USER - The name of the current user.
4.10 SUMMARY
A shell script is simply a text file containing shell commands. What makes shell scripts especially handy is the capability to execute the commands in the file simply by typing the files name as if it were a command. Generally, well want to write a shell script when we recognize either of two situations: v We find ourselves repeating a lengthy series of commands over and over to accomplish one general task. Any time we need to accomplish a task on a fairly frequent basis (daily, weekly, or maybe several times a day), and the task requires more than one UNIX command, the task is a good candidate for packaging in a shell script. v A repeatable procedure needs to be established for a formal activity. Printing a weekly customer invoicing report, for example, might require a complex procedureextracting billing information from a master file, computing the invoice data, setting up the printer, and actually generating the print file. When variables are used they are referred to with the $ symbol in front of them. There are several useful variables available in the shell program. Here are a few: $$ = The PID number of the process executing the shell. $? = Exit status variable. $0 = The name of the command we used to call a program. $1 = The first argument on the command line.
84
$2 = The second argument on the command line. $n = The nth argument on the command line. $* = All the arguments on the command line. $# The number of command line arguments.
The shift command can be used to shift command line arguments to the left, ie $1 becomes the value of $2, $3 shifts into $2, etc. The command, shift 2 will shift 2 places meaning the new value of $1 will be the old value of $3 and so forth.
85
d) all of the above 3) All LINUX systems have the following _________ a) stdin b) stdout c) stderr d) all of the above 4) < redirects the _________ a) stdin b) stdout c) stderr d) none of the above 5) chmod 777 scriptname gives _________ permission. a) Read / execute b) Read / write / execute c) Read / write d) Write / execute 6) The symbol used for command separator ____. a) ; 7) b) ;; c) , d) .
8)
________ runs job in background. a) Sleep 100 b) Sleep 100 & c) & sleep 100 d) sleep & 100
86
9) ____ is the name of the script. a) $1 10) b) $2 c) $0 d) none of the above
shift command
_____________________________________.
a) reassigns the positional parameters, in effect shifting them to the right one notch. b) reassigns the positional parameters, in effect shifting them to the left one notch. c) reassigns the positional parameters, in effect shifting them to the both right & left one notch. d) None of the above. 11) Pipelines are used to ________ commands. a) reverse 12) b) connect c) both a) & b) d) none of these
13)
14)
Following are the internal variables _______. a) $HOME b) $PATH c) all of the above d) none of the above
15)
87
True/False
IV. Essay type questions 1) What is shell? Why shell programming is required.
2) 3) 4) 5) 6) 7) 8) 9) When shell scripts are nt useful? Breifly explain the access permissions related to different types of users. Elaborate all the looping control constructs. Explain all the string-related operators. What are meta characters [wildcards]? Give examples. What are positional parameters? Give examples. Elucidate built-in shell commands and variables. Explain the test command with all options.
V. Further readings and other activities 1. Get more information using man or info or any help command for ksh, sh, bash, tcsh, csh, ksh, ls, vi. EX: 1. $ man sh 2. $ apropos shell Work on all of the example explained in the unit. Some exercises also are given there itself relating to the particular topic.
2. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www.raomvp.bravepages.com/doc/linux/linuxbook.html
88
A complete reference for you to get more information. You can also extract solutions for exercises. Title: UNIX Shell Programming
Author: Stephen G. Kochan and Patrick H. Wood; Howard Sams; ISBN 0-672-48448-X; 1990. An excellent introduction to Bourne and Korn shell programming with lots of illustrative examples. Title: Unix Shell Programming Author: Yashawant Kanitkar Publication: BPB
Chapter 5
File System
inux is inherently multi-user. Your personal settings (and all other personal files) are in your home directory which is /home/your_user_login_name. Many settings are kept in files with names starting with a dot .
LINUX IS CASE-SENSITIVE. Your user login name and password are also case sensitive. Filenames can be up to 256 characters long and can contain letters, numbers, . (dots), _ (underscores), - (dashes), plus some other non-recommended characters. Files with names starting with . are normally not shown by the ls (list) or dir command. Think of these dot files as hidden. Use ls -a (list with the option all) to see these files. / is an equivalent to DOS \ (root directory, meaning the parent of all other directories, or a separator between a directory name and a subdirectory or filename). Under Linux, all directories appear under a single directory tree (there are no DOS-style drive letters). This means directories and files from all physical devices are merged into this single-view tree. Under Linux, as in any multiuser operating system, directories and files have an owner and set of permissions. You will typically be allowed to write only to your home directory which is /home/ your_user_login_name.
Objectives
After completing this section, you will be able to:
89
90
Basic types of files Navigate the file hierarchy Manipulate files and directories Operations on directories Options of inodes Links- hard links and soft links Handle access control Changing access privileges: chmod chmod symbolically and numerically umask masking Privileges Deal with special files and links Mounting volumes and filesystems
91
Normal Files: These are the files you use the most. They can be either text or binary files; however, their internal structure is irrelevant from a System Administrator standpoint. An ls -l on a normal file will look something like this. -rw------------- 1 rao admin 42 May 12 13:09 hello
Directories: These are a special kind of file that contains a list of other files. Although there is a one-toone mapping of inode to disk blocks, there can be a many-to-one mapping from directory entry to inode. When viewing a directory listing using the ls -l command, you can identify directories by their permissions starting with the d character. drwx------------2 rao admin 512 May 12 13:08 public_html
Hard Links:
A hard link is actually a normal directory entry except instead of pointing to a unique file, it points to an already existing file. This gives the illusion that there are two identical files when you do a directory listing. Because a hard link shares an inode, it cannot exist across file systems. Hard links are created with the ln command. For example, given this directory listing using ls -l, we see: -rw------------- 1 rao admin 42 May 12 13:04 hello
When you type $ ln hello goodbye and then perform another directory listing using ls -l, you see: -rw------------- 2 rao admin -rw------------- 2 rao admin 42 May 12 13:04 goodbye 42 May 12 13:04 hello
Notice how this appears to be two separate files that just happen to have the same file lengths. Also note that the link count (second column) has increased from one to two. How can you tell they actually are the same file? Use $ ls -il. Observe: 13180 -rw------------- 2 rao admin 13180 -rw------------2 rao admin 42 May 12 13:04 goodbye 42 May 12 13:04 hello
You can see that both point to the same inode, 13180. Symbolic Links: A symbolic link (sometimes referred to as a symlink) differs from a hard link because it doesnt point to another inode but to another filename. This allows symbolic links to exist
92
across file systems as well as be recognized as a special file to the operating system. Symbolic links are created using the ln -s command. A common thing people do is creating a symbolic link to a directory that has moved. For example, if you are accustomed to accessing the directory for your home page in the subdirectory www, but at the new site you work at, home pages are kept in the public_html directory, you can create a symbolic link from www to public_html using the command ln -s public_html www. Performing an ls -l on the result shows the link. drwx------------- 2 rao admin lrwx------------- 1 rao admin Sockets: Sockets are the means for UNIX to network with other machines. Typically, this is done using network ports; however, the file system has a provision to allow for interprocess communication through socket files. If you need to remove a socket file, use the rm command. Socket files are identified by their permission settings beginning with an s character. An ls l on a socket file looks something like this: srwxrwxrwx 1 root Named Pipes: Similar to sockets, named pipes enable programs to communicate with one another through the file system. You can use the mknod command to create a named pipe. Named pipes are recognizable by their permission settings beginning with the p character. An ls -l on a named pipe looks something like this: prw------------- 1 rao admin Character Devices: These special files are typically found in the /dev directory and provide a mechanism for communicating with system device drivers through the file system one character at a time. They are easily noticed by their permission bits starting with the c character. Each character file contains two special numbers, the major and minor. These two numbers identify which device driver that file communicate. An ls -l on a character device looks something like this: crw-rw-rw- 1 root Block Devices: Block devices also share many characteristics with character devices in that they exist in the /dev directory. They are used to communicate with device drivers. They have major and minor numbers. The key difference is that block devices typically transfer large blocks of data at a time versus one character at a time (A hard disk is a block device, whereas a wheel 21, 4 May 12 13:40 ptyp4 0 May 12 22:02 mypipe admin 0 May 10 14:38 X0 512 May 12 13:08 public_html 11 May 12 13:08 www -> public_html
93
terminal is a character device). Block devices are identified by their permission bits starting with the b character. An ls -l on a block device looks something like this: brw------------- 2 root staff 16, 2 Jul 29 1992 fd0c
Directories are files that list other files. It can be normal files or directories. Also enables a hierarchy to be built. Each directory entry consists of two parts: a file name and an inode number. (An inode is roughly a pointer to a file, see table) The topmost directory is always called /. i.e called the filesystem root. Directory information can only be changed by Linux itself. It also ensures a proper structure to be maintained.
94
By tradition several directories have specialized roles
User-installed programs typically go under the /usr/local hierarchy /mnt is not always present, it is merely a convenience to place all mounted devices under one place
5.5 PATHNAMES
Files can be referred to by relative or absolute pathnames $ cd /usr/sbin/httpd $ cd usr/local/bin/safe-mysqld Absolute pathnames begin with /
95
The absolute pathname refers to one file only.[ reference by root / ] A relative pathname does not begin with / and describes the path from the current directory to find a file, [cd .. or .] Example: $ cd sbin/httpd ; $ cd bin/safe ; $ cd ..
Directories always contain two entries . and .. Used for relative pathnames and navigation. Example:
This last row above shows forced execution of a particular file. If we had simply typed a.out then our PATH environment variable would be used to search for the file.
96
Example: $ rm r somedir Again, full details are available by typing man rm. Removing a file is not considered an operation on the file, It is an operation on the directory. Filenames are merely links.
97
These commands can take many arguments. mkdir can be told to create the whole pathname of directories if they dont exist. Example: $ mkdir p /home/lee/new1/test/directory Will create the directories /home/lee/new1 and /home/lee/new1/test as well as /home/lee/new1/test/directory if they dont already exist. ls arguments control what information is shown and how its sorted, Some are explained later, consult $man ls for full details.
5.11 INODES
Each file is represented by an inode. An inode contains information about: File type (ordinary, directory, FIFO, block device etc.) Owner ID (user the file belongs to) Size (in bytes) Access, creation, and modification times Group ID (group the file belongs to) File permissions Mapping of the file contents (data sectors) Inode layout and location varies with filesystem type The term inode was invented by Dennis M. Ritchie of AT&T.
stat prints the inode contents for files including permissions, size, links, access times etc.
5.13 LINKS
More than one filename can refer to an inode, These file names are links to the file. ln creates links to files. Creates hard links by default. ln -s creates symbolic or soft links. Erasing a file just removes its directory entry, The file is only lost when all entries or it have been removed.
Crucially : A filename is not the file The inode is the file All names are simply links (references) to the inode Vague resemblance to Windows shortcuts
99
Note: Hard links cannot cross filesystems. Inode numbers are filesystem specific.
100
Adding a soft link :
If we replace the test file with another then the symbolic link still works, but the hard one still points to the old file!
101
These may be specified for three sets of users: User Group Everyone
Select who you want to change permissions for (u=user, g=group, o=others, a=all}. Decide whether you want to grant a permission (+), remove(-), or set(=) it. Take the permission that you want to change (r=read, w=write, x=execute). Example: $ chmod gu+w filename Adds write permission for user and group. You can make several changes by separating the settings with commas. Example: $ chmod a-w,gu=rw filename Removes write permission for all, then grants it for the user and group.
103
The section of the filesystem called /proc doesnt contain real files. It contains system status information.
For example:
105
A filesystem can only be unmounted when it is no longer in use. In use includes: Having any file on that filesystem open. Having a shell in a directory on that filesystem.
5.29 SUMMARY
The primary Linux filesystem is Ext2. It has a tree-like hierarchy of directories. Directories merely contain pointers to files(inodes). inodes contain all the information about a file. Also can have multiple links to the same file. Read/Write access is controlled per file. Creation/Deletion of files is controlled by permissions of the directory. Several filesystems can be mounted to create the directory hierarchy. This chapter described the basic overview of how to use a command shell. There is a lot more, which would be very useful especially when writing shell scripts or performing advanced tasks. However the above should be serve as a good beginning to understand what is going on in the system, as well as a starting point from which you can learn more details about Linux shell programs. Remember that the bash shell has its own man page, as well as longer tutorials and documentation available at the Linux Documentation Project website.
(a) Log in and use pwd to discover what the full path of your home directory is. (b) Change directory to /bin and then /tmp. Use pwd to check you got there each time. (c) When in /tmp type cd .. and use pwd to find out where you end up. (d) What is the parent directory of the root of the filesystem? Why is this so? (e) Move back to your home directory. Think of three ways you can do this. 2. Directories (a) Start in your home directory and create a directory called new. (b) Change to the new directory and create a directory called newer. (c) Go to you home directory. Now create a directory under newer called newerstill. There are two ways to do this what are they? (Hint: You dont have to change directories to solve this.) (d) Remove all the directories that youve just created, there are several ways to do this. (e) Create the same directory structure with one command. 3. Links (a) (b) (c) (d) (e) 4. Create a file called test in your home directory (Typing echo 123> test should do this). Now create a hard link to test called h_test and a symbolic link to test called s_test. Find out the inode number of the files. Check you understand why they are what they are. Remove the original file called test. Can you still get at the contents of the original file? What happens if you try cat s_test. Make sure you understand the distinction between h_test, and s_test. Try to make a hard link to your home directory. Why does this fail?
/proc (a) (b) Use the files in /proc to find out how much memory your system has and what processor it is running on. Find out what PCI devices are attached to your machine.
107
(c) (d)
Find out what environment variables are set for your currently running shell using the information in /proc. Hint you can get the process-id of your shell using $$. Whether or not your machine is doing IP forwarding is stored in the file /proc/sys/net/ipv4/ ip_forword. You can cat this file, a value of 1 means that IP forwarding is turned on. Find out whether or not your machine will forward IP.
(e)
Find out how many files are currently open on your system.
_______ command used to change the permissions of your files & directories. a. ls b. chmod c. more d. ls -F
4.
chmod 555 dirname is used ____________________________. a. To protect the files in a directory and all its subdirectories from everyone else on your system. b. To keep yourself from accidentally removing files in a directory. c. To let other people on the system see whats in a directory - and read or edit the files if the file permissions let them - but not rename, remove, or add files. d. none of the above.
5.
chmod 644 filename is used to________________________. a. To let non group users read but not edit the file b. To let anyone read or edit the file c. To make a private file that only you can edit d. none of the above.
6.
For using FTP ____________________________. a. Both computers dont need to be running LINUX
108
b. Both computers need to be running LINUX
c. one computer must be running LINUX & other any operating system d. none of the above. 7. The acronym for EXT2 is ________________________. a. Second Extended File system b. Extended File system c. Expanded File system d. all of the above 8. mount command contains the ____________. a. physical block device that contains the file system b. name of the file system c. both of above d. none of these
IV. Essay type Questions 1. Briefly explain the concept of LINUX file system..
2. Explain the following: i. PATH ii. Absolute pathname and relative pathname. iii. Files in the Directory Tree.
109
iv. Directory Access Permission v. File Access Permission 3. 4. 5. 6. Differentiate among chmod & umask. Explain all the attributes related to ls al . Describe the concept of File Management. Write a note on the following filesystems i /dev ii /poc 7. 8. 9. what is uid? does it relate with access control mechanism of files. How to mount a Shared File system. What is a link? Justify your answer by giving proper examples for its types.
V. Further readings and other activities 1. Get more information using man or info or any help command for sh, bash, csh, ksh, inode, fs, env, set, mount, mknd, id, dev, stat.
2. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www.raomvp.bravepages.com/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. More information on filesystem can be obtained from text book title: Introduction to the Shell programming Author: Yashwanth Kanetkar
110
/home/username where username is the name you log in with. (b) Check that the output of pwd is /bin and /tmp. (c) You should end up in /. This is the root of the filesystem.
(d) The parent of / is itself. You can use ls -lia to show that the inode numbers for . and .. are the same when you are in /. (e) You can move back to your home directory by using any of the following: i. cd ii. cd ~ iii. cd /home/username (Provided your home directory lives under /home) 2. Directories (a) $ cd ; $ mkdir new (c) $ cd ; then either: i. $ cd new/newer ; $ mkdir newerstill ii. $ mkdir new/newer/newerstill (d) Any of the following will work : i. $ cd ; $ cd new/newer ; $ rmdir newerstill ; $ cd .. ; $ rmdir newer ; $ cd .. ; $ rmdir new ii. $ cd ; $ rmdir p new/newer/newerstill ; iii. $ cd ; $ rm fr new/ (e) $ cd ; $ mkdir p new/newer/newerstill 3. Links (a) This is achieved as follows: $ ln test h_test $ ln s test s_test (b) ls -li should show that the inode number of the original file and h_test are identical, h_test is another name for the original file. The inode number for s_test will be different. It is a separate file that contains information about the location of the file it is a link to. (c) After you created the hard link the original file had two names test and h_test. You have removed test but until all names for a file have been removed it is still accessible. In this case you can do cat h_test to see the contents of the file. (b) $ cd new ; $ mkdir newer
111
(d) This should fail with a No such file or directory message. s_test contained a pointer to the file test not the inode number. There is no longer a file named test so this cannot work. Hard links reference a file by its inode number, symbolic links reference it by its name. (e) This is not allowed, as it could stop the filesystem being strictly hierarchical. 4. /proc (a) cat /proc/meminfo should show you memory usage. (b) cat /proc/pci gives a list of all PCI devices. (c) cat /proc/$$/environ will give a list of the environment of your current shell. Each variable is delimited with the nul character (decimal 0). The following will show the output with one variable per line : $ cat /proc/$$/environ | tr \verb|\|000 \verb|\|n (d) See The Exercise (e) $ cat /proc/sys/fs/file-nr
II. Choose appropriate answer 1.d 2. a 3.b 4.b 5.d 6.a 7.a 8. c III. Say True or False 1. True 2. False 3. True 4. False 5. True 6. False
Chapter 6
resented in this chapter are the fundamentals and many useful specifics of the Bourne again shell, currently the most popular of the Linux shells for execution of application programs. Also described are the steps to organize file system and script shell commands, a detailed coverage on partitioning methods of hard disk. Creation and analysis of links, inodes are justified. Disk recovery techniques, maintenance and and space information also enumerated.
OBJECTIVES
After completing this module you should be able to understand and utilize these features of the Linux filesystem: Inode parameters Links creation and analysis Links: relationship with inode Non-native filesystem types Native filesystems types Filesystem checking and recovery Disk usage and free space Disk partitioning utilities Chapter 6 - File System Administration
112
113
Problems with LILO and partitions Filesystem creation A detailed look at fdisk() Block, character and raw Devices
114
size access time mod time inode time block list indirect list Number of bytes in this file. The time at which the file was last accessed. The time at which the file was last modified.
The time at which this inode structure was last modified. A list of disk block numbers which contain the first segment of the file. A list of other block lists.
The modes, link count, user ID, group ID, size and access time are used when generating file listings. Note that the inode does not contain the files name. That information is held in the directory file (see below for details). Example: ls i displays inode numbers of filenames.
stat prints the inode contents for files including permissions, size, links, access times etc.
MSIT 3A Linux Internals Creates hard links by default. ln s creates symbolic or soft links.
115
Erasing a file simply removes its directory entry. Only when all entries for a file have been removed is the file lost. Crucially : A filename is not the file, The inode is the file. All names are simply links (references) to the inode
Note: Hard links cannot cross filesystems. Inode numbers are filesystem specific.
116
If we replace the test file with another then the symbolic link still works, the hard one still points to the old file!
Actually, just a front-end for specific filesystem checkers , e.g. e2fsck The filesystem-specific checker is searched for in these places in this order: /sbin. /etc/fs and /etc. Directories in the PATH environment variable.
117
Common options: -A uses /etc/fstab to ID and check all filesystems in one run. -R skips the root filesystem when the -A option is operative.
118
119
An Extended Partition has its own partition table; pointing to sub-divisions within it. Sub-divisions called Logical partitions (drives).
A common single-disk server might have separate partitions for: Swapping. The / filesystem/directory The /boot filesystem/directory The /home filesystem/directory The /usr filesystem/directory The /var filesystem/directory The /usr/doc filesystem/directory
121
Multiple IDE drive machines always work /boot is on the first primary controller. On mixed IDE/SCSI systems /boot must be on the first IDE primary controller or SCSI ID 0. On multiple SCSI drive systems /boot must be on ID 0 or ID 1.
Partition Magic
The only helpful thing about fdisk screens is that they all prompt with (m for help). Launched without arguments on IDE: [root@jnnce]# /sbin/fdisk using /dev/hda as default device! Command (m for help): v p prints the partition table for current hard disk.
123
Drivers determine how a program reads from and writes to it. For example, a terminal device driver lets programs read typed info in two ways: In raw mode (i.e without driver interpretation). A line at a time with the driver removing erase and kill chars (typos and corrections), so: v The program reads everything on a line. v The number of characters on a line can vary.
6.24 SUMMARY
Commands used to manage file systems
badblocks(8) - Search a device for badblocks. The command badblocks /dev/hda will search the first partition of the first IDE hard drive for badblocks. cfdisk(8) - A partition table manipulator used to create or delete disk partitions. dosfsck(8) - Used to check a msdos filesystem. dumpe2fs(8) - Lists the superblock and blocks group information on the device listed. Use with a command like dumpe2fs /dev/hda2. The filesystem on the device must be a Linux filesystem for this to work. fdformat(8) - Performs s lowlevel format on a floppy disk. Ex: fdformat /dev/fd0H1440. fdisk(8) - Used to add or remove partitions on a disk device. It modifies the partition table entries. fsck(8) - Used to check and/or repair a Linux filesystem. This should only be used on systems that are not mounted.
125
hdparm(8) - Used to get or set the hard disk parameters. mkdosfs(8) - Used to create a msdos filesystem. mke2fs(8) - Create a Linux native filesystem which is called a second extended filesystem. This creates the current version of the Linux filesystem. mkfs(8) - Used to make a Linux filesystem on a device. The command mkfs /dev/hdb1 will create a Linux filesystem on the first partition of the second IDE drive. mkswap(8) - Creates a Linux swap area on a device. mount(8) - Used to mount a filesystem. It supports many types of filesystems. stat(1u) - Used to print out inode information on a file. Usage: stat filename swapoff(8) - Used to de-activate a swap partition. swapon(8) - Used to activate a swap partition. tune2fs(8) - Used to adjust filesystem parameters that are tunable on a Linux second extended filesystem. The filesystem must not be mounted write when this operation is performed. Can adjust maximum mount counts between filesystem checks, the time between filesystem checks, the amount of reserved blocks, and other parameters. umount(8) - Unmount a filesystem.
126
(f) What happens if you try cat s_ test. Make sure you understand the destinction between h_test and s-_ test. (g) Try to make a hard link to your home directory. Why does this fail? 2. Creating Filesystems and Formatting. (a) Identify and use the command string needed to create the following on a floppy disk: i. An Ext2 filesystem ii. A DOS filesystem iii. An IS09660 CD-ROM filesystem (b) To test your DOS filesystem, cp a long filename file to it. What happens to the filename? (c) Mount the ISO9660 formatted disk under /mnt/floppy to prove it is readable. (d) Identify and use the command string needed to do the following to a floppy disk: i. Low-level format the disk. ii. Add a DOS fs to a low-level formatted disk. (e) Try using tar to write to a floppy disk without a filesystem on it (you may have to low-level format the disk to remove an existing fs). 3. Checking and Repairing Filesystems. (a) Find the appropriate man pages and, hence commands to: i. Locate bad blocks on an Ext2 device. ii. Find and mark the bad blocks on DOS/FAT floppies. (b) Use e2fsck to force checking and automatically repair an Ext2 formatted floppy. 4. Creating, Modifying and Deleting Partitions.
It is not wise to practice disk partitioning on important filesystems. It can be done, but mistakes may be unrecoverable. So we ask you to do the following partitioning questions on a floppy. Most people wont be able to make mountable filesystems on a floppy (you need to make a block device file first), but you should get some safe practice on fdisk. You may only be able to do these floppy-based questions using recent versions of fdisk. (a) (b) Delete all existing partitions from your floppy. Create 2 new primary partitions: i. 1 with an Ext2 system ID ii. 1 with a Win95 FAT32 system ID.
127
Save the new partition table and exit fdisk. Re-enter fdisk and check the floppys partition table contains the correct partitions. Delete the FAT32 partition and replace it with two FAT32 logical drives.
II. Choose the correct answer: 1. Every file / directory is specified by an _____.
a) Link b) inode c) name d) all of these. 2. ln creates links to ___________. a) files b) system programs c) Application programs d) all of these. 3. ln -s creates _____ links. a) Kernel b) shell c) symbolic or soft d) all of these. 4. Ext2 is _________________________. a) Network File System b) Native File System c) NetBios System d) None of the above 5. ____ checks and repairs Linux filesystems. a) fips b) diskdruid c) fsck d) All of the above
128
IV. Essay Type Questions
1) 2) 3) 4) 5) 6) 7) 8)
What are block, character and raw devices? Write brief information. Explain with options e2fsck. Explain the changes in filesystem when du and df commands are executed. Explain how the recovery of Linux filesystems are made. Describe how the Native Linux filesystems are made? Give the types. Desctibe the inode table entries in detail. Elucidate common disk partitioning tools. Mention all fdisk interactive commands.
V. Further readings and other activities 1. Get more information using man or info or any help command for
e2fsck, du, df, tty, passwd, group, ln EX: 1. $ man du 2. $ apropos bash Check the amount of space used, amount of space free for different drives and different directories. 2. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.geocities.com/raomvp/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. Title: principles of unix programming Auihors: Sumitabha Das
129
(b) The answer depends on your system. In recent Red Hat distributions inode number 1 is / proc and number 3 is /proc/uptime. (c) This is achieved as follows: $ ln test h_test $ ln s test s_test (d) ls -li should show that the inode number of the original file and h_test are identical h_test is another name for the original file. The inode number for s_test will be different. It is a seperate file that contains information about the location of the file it is a link to. (e) After you created the hard link the original file had two names test and h_test. You have removed test but until all names for a file have been removed it is still accessible. In this case you can do cat h_test to see the contents of the file. (f) This should fail with a no such file or directory message. s_test contained a pointer to the file test not the inode number. There is no longer a file named test so this cannot work. Hard links reference a file by its inode number, symbolic links reference it by its name. (g) This is not allowed, as it could stop the filesystem being strictly hierarchical. 2. Creating Filesystems and Formatting. (a) These are typical solutions, but there are others: i. $ mke2fs /dev/fd0 ii. $ mkdosfs /dev/fd0 iii. $ mkdosfs /dev/fd0 (b) The filename should be shortened to 8 chars, without warning . . . could be tricky! (c) Yes, you can mount a floppy drive on Linux with a CD-ROM format. Indeed, you can actually mount an ISO9660 formatted disk image (i.e. a single file) of an entire Linux directory tree. Trust me, it isnt as daft as it sounds! (d) Something like this: i. $ fdformat /dev/fd0h1440 ii. Add a DOS fs to a low-level formatted disk. (e) Use a command something like this: $ tar c filenames > /dev/fd0
130
3. Checking and Repairing Filesystems (a) apropos should yield: i. badblocks (8). ii. mbadblocks (1). (b) e2fsck p f /dev/fd0
Assuming that your floppy is actually OK, you will hardly get any feedback on stdout. 4. Creating, Modifying and Deleting Partitions. You probably cant do these floppy-based questions on old versions of fdisk. (a) Use $ fdisk /dev/fd0 followed by the d interactive command. (b) Use the n interactive command twice, followed by: i. command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 83 ii. command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): b (c) Use the w interactive command followed by the q interactive command. (d) $ fdisk /dev/fd0 followed by the p interactive command (e) Your screen should look something like this:
131
command action e extended p primary partition (1-4) e command (m for help): p Disk /dev/fd0: 2 heads. 18 sectors, 80 cylinders units = cylinders of 36 * 512 bytes
Using default value 41 Last cylinder or +size or +sizeM or +sizeK (41-80, default 80): 60 command (m for help): n command action l logical (5 or over) p primary partition (1-4) l
command (m for help): p Disk /dev/fd0: 2 heads. 18 sectors, 80 cylinders units = cylinders of 36 * 512 bytes
132
command (m for help): t partition number (1-6): 5 Hex code (type L to list codes): b Changed system type of partition 5 to b (Win95 FAT32) command (m for help): t partition number (1-6): 6 Hex code (type L to list codes): b Changed system type of partition 6 to b (Win95 FAT32) command (m for help): p Disk /dev/fd0: 2 heads. 18 sectors, 80 cylinders units = cylinders of 36 * 512 bytes
II. Choose the correct answer: 1. b 2. a 3. c 4. b III. Say True or False 1. True 2. True 3. True
5. d
4. False
Chapter 7
System Administration
o far in this book, youve seen how to use Linux for many different tasks. However, there are some issues we havent dealt with because they are used rarely or only by a single administrator (who may be the only user).
This chapter covers the most important things that you need to know about system administration under Linux in sufficient detail to start using the system comfortably. In order to keep the chapter manageable, it covers just the basics and omits many important details. The general actions a system administrator must perform to keep filesystems performing smoothly are the following:v v v v v v v Check filesystems for corrupt sectors Check filesystems for integrity and correct i-node tables Check file permissions and ownerships to ensure proper access Make filesystems (local and remote) available to users as necessary Check the Linux systems disk space Management of users with respect to security and data Perform regular backups for data security
133
134 Objectives
At the end of this unit, You would be able to know and expertise the following concepts of system administration. The superuser account User accounts /etc/passwd Groups Managing Linux users User reference files User modifications Examples of making changes to permissions Some administration commands
135
$ vi /etc/passwd root::0:0:root:/root:/bin/bash
bin:*:1:1:bin:/bin: daemon:*:2:2:daemon:/sbin: adm:*:3:4:adm:/var/adm: lp:*:4:7:lp:/var/spool/lpd: sync:*:5:0:sync:/sbin:/bin/sync shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown halt:*:7:0:halt:/sbin:/sbin/halt mail:*:8:12:mail:/var/spool/mail: news:*:9:13:news:/usr/lib/news: uucp:*:10:14:uucp:/var/spool/uucppublic: operator:*:11:0:operator:/root:/bin/bash nobody:*:-1:100:nobody:/dev/null: Each line in the /etc/passwd file is composed of seven fields, separated by a full colon. If there is nothing to be entered in a field, the field is left blank, but the colons are retained to make sure each line has seven fields (which also means each line will have six colons). The seven fields (from left to right on each line) are: A unique identifier for the user. The users password (encrypted). A unique number that identifies the user to the operating system. A unique number that identifies the users group (for file permissions). Usually the users real name, but sometimes phone numbers, departments, and so on. The directory in which users are placed when they log in. The command executed when the user logs in, normally a shell.
user name password user ID (UID) group ID (GID) comment home directory login command
7.3 GROUPS
Group information is maintained in the file /etc/group, which is similar in layout to the /etc/ passwd file. The default /etc/group file from a newly installed Linux system is shown below.
136
$vi /etc/group root::0:root bin::1:root,bin,daemon daemon::2:root,bin,daemon sys::3:root,bin,adm adm::4:root,adm,daemon tty::5: disk::6:root,adm lp::7:lp mem::8: kmem::9: wheel::10:root floppy::11:root mail::12:mail news::13:news uucp::14:uucp man::15:man users::100:games nogroup::-1:
Each line in the file has four fields separated by colons. Two colons together mean that the field is empty and has no value specified. Each line in the file follows this format: v group name:group password:group ID:users
Each group has a line of its own in the file. The fields in the /etc/group file (from left to right) are listed as follows: v group name- A unique name usually of eight characters or less (usually standard alphanumeric characters only). v password- Usually left as an asterisk or blank, but a password can be assigned that a user must enter to join the group. Not all versions of Linux or UNIX use this field, and it is left in the file for backward compatibility reasons. v group ID (GID)- A unique number for each group, used by the operating system. v users- A list of all user IDs that belong to that group.
137
Every Linux system has a number of default groups which belong to the operating system, usually called bin, mail, uucp, sys, and so on. You can see the system-dependent groups in the default /etc/group file as shown by vi editor. In that file, all but the last two entries are system groups. You should never allow users to belong to one of these groups because it gives them access permissions that can be the same as roots. Only system logins should have access to these operating system groups.
138
v passwd (1) - Used to update a users password. The command passwd username will set the password for the given user. v pwconv (8) - Used to create the file /etc/shadow from the file /etc/passwd to convert to shadow passwords. v pwunconv (8) - Uses the files /etc/passwd and /etc/shadow to create /etc/passwd, then deletes /etc/shadow to convert from shadow passwords. v su (1) - run a shell with substitute user and group IDs v useradd (8) - Create a new user or update default new user information v userdel (8) - Delete a user account and their files from the system. The command userdel -r newuser will remove the user and deletes their home directory. v usermod (8) - Modify a user account. Other useful commands/examples find / -user username -ls chown -R myuser /home/myuser chmod +s filename Gives a list of all files owned by username. Changes ownership of all files in mysuer home directory to myuser. SETS THE UID
139
To remove a user, while logged in as root, type userdel -r username. This will remove the users home directory. You can delete the user without the -r option and delete the users home directory manually. If the group the user was in, is no longer needed, you may delete it by editing the /etc/group file. The file /etc/aliases is where the users real name is matched to their user name for e-mail accounts. Add users to this file in the form: Firstname,Lastname:username
chmod 764 myfile chmod 751 myfile chmod +s myfile chmod go=rx myfile
Below are examples of making changes to owner and group: chown mark test1 chgrp mark test1 Changes the owner of the file test1 to the user Mark. Changes the file test1 to belong to the group mark.
140
(as root) Configure mouse, soundcard, keyboard, X-windows, and system services. There are many distibution-specific configuration utilities, setup is the default on RedHat. Mandrake 7.0 offers very nice DrakConf. linuxconf
(as root, either in text mode or in the X terminal). You can access and change hundreds of networks setting from here. ReadHats network configuration utility netconf is a subset of linuxconf, therefore it is simpler and sometimes easier to use. mouseconf
(as root). Simple tool to configure your mouse (after the initial installation). Mandrake includes also an alternative mousedrake. kudzu
(as root). Automatically determines and configures your hardware. If having mysterious problems with your mouse (or other serial hardware), you may want to disable kudzu, so it does not run on the system startup. You can run it manually when you need it. timeconfig
(as root) Set the timezone for your system. It is important to keep the timezone correct. setclock
(as root). Set your computer hardware clock from the current linux system time. Use the command date first to set up the linux system time. E.g., We could change the date and time to 2005-12-31 23:57 using this command: date 123123572005. dateconfig&
(in X-terminal, as root else you will be asked for the root password). An excellent GUI utility to set our operating system and hardware clock and timezone, and tell our BIOS to keep time in UTC. We ignore the previous two commands.
141
xvidtune
(in X-terminal). Adjust the settings for your monitor display for all resolutions so as to eliminate black bands, shift the display right/left/up/down, etc. (First use the knobs on your monitor to fit your text mode correctly on the screen). Then use xvidtune to adjust the monitor frequencies for each resolution so it fits well in your screen. To make the changes permanent, display the frequencies on the screen and then transfer them to the setup file /etc/X11/XF86Config. On newer monitors, you may really prefer to adjust your monitor using the built-in monitor settingsxvidtune is for older monitors which do not have the capability to remember their settings. SuperProbe
(as root). A utility to determine the type of the video card and the amount of its memory. lspci
Show info on your motherboard and what cards are inserted into the pci extension slots. Our older computer has ISA slots (or EISA) slots, no pci. lsdev
Display info about your hardware (DMA, IRQ, IO ports). chkconfig list | more
To start a service right now, We may use something like (starts an proxy server): service squid start To re-start samba networking, We may use: service smb restart fsck -t ext2 /dev/hda2
(=file system check, as root) Check and repair a filesystem, e.g., after an unclean shutdown due to a power failure. The above example performs the check on the partition hda2, filesystem type ext2. You definitely want to unmount the partitions or boot Linux in the single mode to perform this (type linux single at the LILO prompt or use init 1 as root to enter the single user mode). If errors are found during the filesystem checkup, We accept the defaults for repair. The problems with unclean shutdown can be avoided if you use a journalizing file system (e.g., ext3) on your system (highly recommended). mkbootdisk device /dev/fd0 2.4.2-3
Make an emergency boot floppy. You are typically asked if you would like to make a boot disk during the system installation. The above command shows how to make it after install, on the first floppy drive (/ dev/fd0). Your kernel name (needed in the command, here 2.4.2-3) can be determined either by running uname -a or ls /lib/modules.
All access to a Linux system is through a user account. Every user must be set up by the system administrator, with the sole exception of the root account (and some system accounts that users seldom, if ever, use). While many Linux systems only have one user, that user should not use the root account for dailyaccess. Most systems allow several users to gain access, either through multiple users on the main console, through a modem or network, or over hard-wired terminals. Knowing how to set up and manage user accounts and their associated directories and files is an important aspect of Linux system administration.
All Unix passwords, regardless of length (up to a maximum of 8 characters), are stored in the password file as encrypted strings of _________. a. b. c. 13 characters 16 characters 8 characters
3.
143
c. 4.
userdel
Unix systems keeps user account information, including one-way encrypted passwords, in a text file called ________. a. b. c. /etc/password /etc/passwd /etc/pwd
5.
The /etc/shadow file contents are read _____________. a. b. c. only by the current account only by the root account both a & b
6.
df command gives the information about ______ space. a. b. c. free space used space none of the above
7.
The / file-system, mounted on /dev/hda1, contains the_____. a. b. c. d. Linux kernel device drivers Other directories All of the above.
III. Say True or False 1. Passwd command is used for changing the password.
2. 3. 4. The root account has security restrictions. The username is at atleast 8 characters long. Change the password using su command.
144
IV. Essay type Questions 1. Explain the different steps of creating user account.
2. 3. Describe the total responsibility of a system administrator. Write a note on the following. i. ii. disabling user accounts removing user accounts
iii. changing user passwords iv. starting & stopping processes 4. 5. 6. Elaborate the commands used for system administration. Explain the technique of managing /etc/passwd and /etc/group files. Explain the technique of managing and changing permissions using atleast two commands.
V. Further readings and other activities 1. Get more information using man or info or any help command for sh, bash, csh, ksh, inode, fs, env, set, mount, mknd, id, dev, stat.
2. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.geocities.com/raomvp/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. More information on filesystem can be obtained from text book title: Introduction to the Shell programming Author: Yashwanth Kanetkar
VI. Solutions I. Choose appropriate answer 1.c 2.a 3.c 4.b 5.b II. Say True or False 1.true 2.false 3.false 4.false
6.a 7.d
Chapter 8
here are many text editors available for the Linux system. Two of the most popular are vi (which is actually an alias to the elvis editor) and emacs. Both provide basic editing functions such as inserting and deleting text, reading and writing of external files, text searching, and copying and moving text. vi is a full-screen editor that has two modes: command mode and text mode. emacs is an extendible and powerful editor that is highly configurable to suit a variety of editing tasks (such as programming, document writing, and changing user or system files).
Objectives
At the end of this unit, You would be able to understand and expertise the following concets. Linux VI editor The emacs editor System and network configuration commands X Configuration utilities Library and kernel dependency management tools General Diagnostic function calls To remotely use Xwindows from Ms Windows Network application commands
145
The following is a summary of the more essential commands of vi. You should consult the vi man page for more details on the many other vi commands. A SUMMARY OF COMMANDS insert mode, (ESC to exit insert mode) allows text to be entered on the screen Append to right mode Move to the occurrence of word Locate the next occurance Advance to the next word Advance to the next end of a word Move to the previous word Move backward 3 words delete line delete 3 lines Delete remainder of a line Delete word Delete character Open space for new line below the cursor line Open a line above the cursor Move back a word in append mode Undo last Undo all changes to current line In command mode, repeat the last text changing the command on the current line
:w newfilename save the file to newfilename from the command mode :wq :q! save and quit quit without saving
147
r J s cw c cc h H L M G 0 (zero)
replace then typa a character ot be replaced with r then return to break up a line join 2 lines substitute (sentence) typed text over a character, ESC when done change word change part of a line from the cursor to the end of the line substitute new text for aline, ESC when done move the cursor back one space move the cursor to the highest line on the screen move the cursor to the lowest line on the screen position the cursor at the midpoint on the screen last line in the file Move the cursor to the beginning of the line it is on
view filename Open a file for viewing only set number set nonumber Options: number autoindent (ai) showmatch tabstop=4 wrapmargine(wm) :2 copy 4 :1,4 :n when line is wrapped (80-value) Place a copy of line 2 after line 4. copy 7 (lines 1-4) Access the next file for editing ctrl-d to move to the left match brackets and parenthesis Turn on line numbers Turn off line numbers
emacs has become the editor of choice for many users because of its online help facility and its extensive collection of editing commands. emacs is advanced and sophisticated text editor. For programmers, emacs is especially attractive because it can be configured to format source code for a variety of languages such as C, C++, and Lisp. emacs is somewhat easier to learn than vi, but it also features a much larger set of commands. There are likely 3 versions of emacs installed on your system: (1) text-only: type emacs in a text (not X-windows) terminal (2) graphical-mode: type emacs in an X-windows terminal and (3) X-windows mode: type xemacs in an X-windows terminal. STARTING EMACS emacs is invoked from the command line by entering emacs. To start emacs with a file to be edited, enter emacs filename. If you start emacs with a file, the screen will display the contents starting from the first line. Note the two lines at the bottom of the screen. The first of these lines, known as the mode line, displays the name of the file being edited and which part of the file that you are looking at (for example, TOP, 20%, BOT). The last line on the screen is the echo line, which emacs uses to display system messages and as a prompt for more input. A SUMMARY OF COMMANDS The following table is a summary of the strictly essential commands that you will need for basic editing in emacs. The emacs man page should be consulted for a more comprehensive description of the full emacs command set. Files are loaded into the following types of buffers: Fundamental - For text files C mode Shell mode
move forward a page move back a page move cursor to beginning of the current line move cursor to the end of the current line Get a list of help options, Ctrl h again describes what they are. Ctrl h, then t tutorial, i -info reader
149
Ctrl a,Ctrl space Set the mark Ctrl w Ctrl y Alt w Ctrl k Alt y Ctrl x x a Ctrl s Ctrl r Alt Ctrl s Alt % Alt x string Deletes the text in the region (between the mark and the cursor) Paste the text in the buffer at the current cursor location Copy the text in the region kill text Replace yanked text with the previous block from the kill ring.(the ring of buffers where deleted and copied text is stored) Copy the region into register a Search for text Search backward Search for something like jo.*n matching john, joan, etc replace a string, space to replace, delete to skip, period to stop. replace all the string without prompts
Ctrl x - make the following commands available (also allows macros): (Ctrl x e - to perform the macro) Exit the editor Save the current file Find another file to edit Switch to another buffer Present a list of available buffers Switch between two windows Moves back one character. Deletes the current character. Moves forward one character. Cancels the current command. Enters emacs online help. Moves forward to the next line.
Ctrx x ...commands... Ctrlx Ctrl c Ctrl s Ctrl f b Ctrl b o C-b C-d C-f C-g C-h C-n
150
C-p C-s C-v M-v C-x u C-x C-c C-x C-s Moves back to the previous line. Searches forward for a string. Scrolls forward one screen. Scrolls backward one screen. Undoes the last edit. Exits emacs. Saves the buffer to a file.
8.4 X CONFIGURATION
v v XF86Setup - A newer X configuration program with a GUI interface which modifies the / etc/X11/XF86Config configuration file. xf86config - An older X configuration program with a text based interface. It also modifies the /etc/X11/XF86Config configuration file.
151
v v v
Xconfigurator - The Redhat tool used during system setup to configure X. SuperProbe - A program that probes the video card to determine its type for use with setting up X. xvidtune - This program will test video modes on the fly without modification to your X configuration. Read the usr/X11R6/lib/X11/doc/VideoModes.doc file before running this program.
152
Other: v env - List the current environment variables. v printenv - Print a copy of the environment.
v set - Shows how the environment is set up. This command can be very useful when debugging the environment. v runlevel - List the current and previous runlevel. v uname - Print system information. In my case, it prints Linux. v dmesg - Show the last kernel messages printed during the last boot.
153
v The command X -probeonly > /tmp/test.out 2>&1 lists supported chipsets and other useful information. v The command X > /tmp/test.out 2>&1 runs X bare. Use Ctrl-Alt-BS key combination, then examine the contents of the output file to help debug X startup problems.
(in X terminal) File manager and web browser in one. Very nice, in many very comptetitive to mozilla. Comes with KDE. pine
A good, old-fashioned, text-mode mail reader. Another old-fashioned and standard one is elm. Your mozilla mail will read the mail from your Internet account. pine will let you read the local mail, e.g. the mail your son or a cron process sends to you from a computer on your home network. The command mail could also be used for reading/composing mail, but it would be inconvenientit is meant to be used in scripts for automation. mutt
A really basic but extremally useful and fast mail reader. mail
A basic operating system tool for e-mail. Look at the previous commands for a better e-mail reader. mail is good if you wanted to send an e-mail from a shell script. kmail &
(in X-terminal) Nice, GUI mail program. We use kmail, it is much better than netscape mail. We can have multiple accounts and retrieve mail from the smtp (local) server and pop3 servers (internet service provider) to the same mailbox. Simple and elegant. Supports digital signatures. licq &
(in X terminal) An icq instant messaging client. Another good one is kxicq. Older distributions dont have an icq client installed, you may have to do download one and install it.
154
talk username1
Talk to another user currently logged on your machine (or use talkusername1@machinename to talk to a user on a different computer) . To accept the invitation to the conversation, type the command talk username2. If somebody is trying to talk to you and it disrupts your work, your may use the command mesg n to refuse accepting messages. You may want to use who or rwho to determine the users who are currently logged-in. talk is one of the old-fashioned standard UNIX tools, yet it still can be cool and useful in some situations. telnet server
Connect to another machine using the TELNET protocol. Use a remote machine name or IP address. You will be prompted for your login name and passwordyou must have an account on the remote machine to login. Telnet will connect you to another machine and let you operate on it as if you were sitting at its keyboard (almost). Telnet is not very secureeverything you type moves through the networks in open text, even your password! A competent system administrator on a computer on-route can read what you type. Use ssh (requires some setup) for encrypted transmission. ftp server Ftp another machine. (There is also ncftp which adds extra features and gftp for GUI .) Ftp is good for copying files to/from a remote machine. Try user anonymous if you dont have an account on the remote server. After connection, use ? to see the list of available ftp commands. The essential ftp commands are: ls (see the files on the remote system), ASCII,binary (set the file transfer mode to either text or binary, important that you select the proper one ), get (copy a file from the remote system to the local system), mget (get many files at once), put (copy a file from the local system to the remote system), mput (put many files at once), bye (disconnect). For automation in a script, you may want to use ncftpput and ncftpget, for example:
8.9 SUMMARY
There are many other editors also present. pico filename Edit a text file using the simple and standard text editor called pico. Use <Ctrl>x to exit. There are many text editors for Linux, including several GUI-based. A brand new clone of pico (GPLed) is nano. kwrite (in X terminal) Very nice, advanced text editor. Supports vertical text selection!
155
kate, kedit, gedit (in X terminal). Simple yet nice text editors (GUI based).
gxedit (in X terminal) Another multi-purpose, feature packed text editor. This one even has timed backup.
latte (in X terminal) Code editor, i.e., plain text editor meant for writing programs.
nedit (in X terminal) Another programmer editor. Very nice and loaded.
bluefish (in X terminal) html editor (source with syntax highlighting and many tools and options).
The following are the Linux commands _____ a. b. c. d. ATTRIB BACKUP RESTORE None of the above
156
3. The equivalent for COPY in Linux is _____ a. b. c. d. mv & rm cp both a & b none of the above.
II. Say True or False 1. In Linux operating system filenames are limited to 8 characters. True/False
2. 3. 4. Linux operating system is case sensitive. ifconfig is used for netwoks ip address setting. free - Show system memory availability and usage True/False True/False True/False
III. Essay type questions 1. List out the comparisons between DOS-to-LINUX.
2. 3. 4. 5. 6. Explian different modes of vi-editor and describe emacs editor. Describe the network configuration commands. Explain the X Configuration utilities Explain the Network application commands Describe how to remotely use Xwindows from Ms Windows.
IV. Further readings and other activities 1. Get more information using help commands aboutVi, ed, red, gEdit, vim, Emacs, ex, sed, awk, mtools
157
2.
Install from Linux source cd, The dos emulation package by name DOSEMU and work on all dos emulation commands.
3. For further readings you can refer the following books Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.geocities.com/raomvp/doc/linux/linuxbook.html A complete reference for you to get more information. You can also extract solutions for exercises. Title: Power Tools, second edition, Author: Jerry Peek, Tim OReilly, Mike Loukides, and others; OReilly & Associates; ISBN 156592-260-3; 1997. A huge collection of tips, techniques, and concepts for making intermediate users into advanced users. Title: Learning the vi Editor Author: Linda Lamb; OReilly & Associates; ISBN 0-937175-67-6; 1992. A complete introduction to vi, structured like LINUX in a Nutshell.
VI. Solutions I. Choose the correct answer 1.a 2.d 3.a 4.d II. Say True or False 1.False 2.True 3.True 4.True
Chapter 9
Installation of Linux
158
159
OBJECTIVES
At the end of this unit, You would be able to install and configure the Linux operating system and know and expertise the following concepts of system installation. Devices of installation Partitioning hard disk Partition sizes Mount points Mounting partitions at startup The fstab file Know your hardware Creating the Linux boot disk Making a bootable diskette under MS-DOS Making a diskette under a Linux-Like OS Beginning the installation of Linux Installation options - class and method Manual configurations Package installations Standard linux partition filesystem types Network administration tools
160
/dev/sdc3 First SCSI interface, device id 3
/dev/cdrom CD ROM drive /dev/mouse Mouse device, sometimes a pointer to another device such as /dev/psaux, a ps/2 mouse driver. primary primary secondary secondary IDE master IDE slave IDE master IDE slave /dev/had /dev/hdb /dev/hdc /dev/hdd
If you are setting up a computer you will be learning Linux on or installing several operating systems, you may want one Linux native partition [3 to 5 GB total] per Linux install. If, however, you are setting up a dedicated high performance server, you may want to set up several Linux native partitions and install various parts of the operating system on separate ones similar to the following recommendation or some modification thereof:
161
1. 2. 3.
/ - Root size of 200MB. /usr - Holds local software. Minimum of 700MB, Recommended 1.7 GB or more. /var - Holds mail, spool, and log files. Recommended size of 400MB
4. /home -The rest of the disk, Used for user storage and in a multi user system, is where most data will be stored. In systems that we will use at home or learn on, We normally use one linux native partition per Linux install. If we are installing Redhat and Slackware we might make two 3GB partitions. We like to make the size of our Linux native [ext2] partitions about 3GB depending on the amount of hard drive space we have and the number of systems we are installing. This is because Linux takes about 0.8G to 1.3G for a full install and some room is left over for expansion. If installing only one Linux system, we like to have 4-6GB. One thing we like to do when installing a system to be shared with Windows, which can make life convenient and save your data, is to make a large partition on a large hard drive that is FAT32. Since Linux can mount this and most if not all Windows operating systems can see this, your data can be available in a common filesystem on this partition.
162
The name of the device such as /dev/hda1
The mount point. Use / for root. Other typical mount points are /dos for DOS, swap or none for the swap partition, and /mnt/floppy for /dev/fd0 (the floppy drive). The type of filesystem. They are: mini, ext, ext2(linux native), xiafs, msdos, hpfs, ntfs, fat32, iso9660(CD-ROM), nfs, swap (for swap space). The mount options for use with the filesystem. Each filesystem type has different mount options. Read the mount man page to see possible options. ro= read only, user- allows normal users to mount the device. The frequency the filesystem needs to be dumped (backed up) by the dump command. For ext2, normally make it 1, for others make it 0. 0 or nothing means it is not dumped. If 1, it is backed up during a system backup. A number telling the order in which the filesystems should be checked at reboot time by the fsck program. Your root should be 1, others are in ascending order or 0 to not be checked. To determine your hard drives partitions and see what each partition holds which operating system, you may use the fdisk program. Use p option to see a list of current partitions, then you can add them to your fstab file.
These are the options: v defaults - Use the default options of rw, suid, dev,exec,auto, nouser, and async. v auto - Auto detect the type of filesystem.
163
v noauto - The -a option will not mount the filesystem. v owner v ro - Read only v rw - Read and write allowed v user - Users have permission to mount this filesystem v users - Allows a user to mount and another user to unmount the filesystem The /proc directory is required for tracking processes in memory (RAM). The directories /data, /dos, and /slackw in this example must exist or their mounts will fail.
164
* IP address * netmask * gateway address * domain name servers IP address * domain name * hostname * types of network(s) card(s) (makes and model) * number of card(s) (makes and model).
165
166
Step 3
Finally, we choose the kind of mouse type we use and if this mouse has two or three buttons. If you have a mouse with just two buttons, you can select the option named Emulate 3 Buttons and click both mouse buttons at the same time to act as the middle mouse button. Once we have completed the above three steps, we are ready to begin the installation of Red Hat Linux.
167
On the next screen you will see the LILO Configuration screen. LILO, the LInux LOader, is software that can be used to start Linux on your computer. From this screen, you will see different configurable options related to LILO. The first option is:- Create boot disk The Create boot disk option is checked by default. If you do not want to create a boot disk, you should deselect this option. Also, this option must be checked if you decide to not install LILO on the MBR (the Master Boot Record) or if you are not installing LILO at all.
The second option is:- Do not install LILO This option allows you to skip installing LILO if you use a boot disk rather than LILO to start your system.
The third option (the one that we will chose) installs LILO in your Linux system and gives you the choice to install LILO boot record on: Master Boot Record (MBR) First Sector of Boot Partition Usually, if Linux is the only Operating System on your machine (and this must be the case in a custum installation), you should choose the Master Boot Record (MBR) option.
Network Configuration After that, you need to configure your network. If you have multiple Ethernet devices, each device will have its own configuration screen.
Firewall Configuration The latest release of Red Hat Linux now offers the possibility to configure a Firewall during installation. This is OK for the average end user but NOT for serious Firewall security. From the next screen that appears, you will see three different security levels available, choose the No firewall option and click Next.
Language Support Selection From here the installation will ask you to choose the default language that will be used on your Linux system. Time Zone Selection On the next screen, you will have the opportunity to set your time zone. Once selected click Next.
168
Account Configuration
After the clock has been configured, you need to give your system a root password account. Authentication Configuration Finally, the last stage is the authentication configuration. For Authentication Configuration dont forget to select: Enable MD5 passwords Enable Shadow passwords Enable MD5 passwords - allows a long password to be used (up to 256 characters), instead of the Unix standard eight letters or less. Enable shadow passwords - provides a very secure method of retaining passwords for you. All passwords are stored in a file named shadow, which is readable only by the super-user root. Enable NIS, LDAP, and Kerberos doesnt need to be selected. Selecting Package Groups After your partitions have been configured and selected for formatting and configurations have been set for your specific system, you are ready to select packages for installation. By default, continue by pressing next key till you get message linux is installed successfully.
169
packagename-2.3.4 and place the extracted information here. 5 6 7 Typically the following outlines the rest of the steps but they will vary from package to package. Go into the created subdirectory and type ./configure. Type make all or ./make Type make install or ./make install
Installing Redhat Packages The RedHat package manager installation utility is called rpm. rpm is supposed to be an intelligent software package manager. To get help Queries the database of installed packages to see if this package is installed or what version of it is installed. Installs mypack. Upgrades mypack. To query with details about the package. Gives a list of files this package installs. Removes the package mypack-1.2.2.
rpm help rpm -q mypack-1.0.1.rpm rpm ivh mypack-1.0-1.rpm rpm uvh mypack-2.0-1.rpm rpm qip mypack-1.2.2.rpm rpm qlp mypack-1.2.2.rpm rpm -e mypack-1.2.2
It is the filesystem used in the Minix operating system, the first to run under Linux. It has a number of shortcomings: a 64MB partition size limit, short filenames, a single time stamp, etc. It remains useful for floppies and RAM disks. ext
It is an elaborate extension of the minix filesystem. It has been completely superseded by the second version of the extended filesystem (ext2) and will eventually be removed from the kernel. ext2
It is the high performance disk filesystem used by Linux for fixed disks as well as removable media. The second extended filesystem was designed as an extension of the extended file system (ext). ext2
170
offers the best performance (in terms of speed and CPU usage) of the filesystems supported under Linux. In short, ext2 is the main (default, typical) Linux filesystem. ext3
It is an extension of the ext2 filesystem with journalizing. It is backward and forward compatible with ext2. It means that ext2 can be converted into ext3 without reformatting or data loss (just re-mounting the partition is required). ext3 can be changed back to ext2, also without data loss. It is highly recommended that you use this filesystem. xiafs
It was designed and implemented to be a stable, safe filesystem by extending the Minix filesystem code. It provides the basic most requested features without undue complexity. The xia filesystem is no longer actively developed or maintained. It is used infrequently. msdos
It is the filesystem used by DOS, Windows, and some OS/2 computers. msdos filenames can be no longer than 8 characters followed by an optional period and 3 character extension. umsdos
It is an extended DOS filesystem used by Linux. It adds capability for long filenames, UID/GID, POSIX permissions, and special files (devices, named pipes, etc.) under the DOS filesystem, without sacrificing compatibility with DOS. vfat
It is an extended DOS filesystem used by Microsoft Windows95 and Windows NT. VFAT adds capability for long filenames under the MSDOS filesystem. proc
It is a pseudo-filesystem which is used as an interface to kernel data structures rather than reading and interpreting /dev/kmem. In particular, its files do not take up disk space. See $ man 5 proc. iso9660
It is a CD-ROM filesystem type conforming to the ISO 9660 standard. Two extensions (listed below) are automatically supported. v High Sierra Linux supports High Sierra, the precursor to the ISO 9660 standard for CDROM filesystems. It is automatically recognized within the iso9660 filesystem support under Linux. v Rock Ridge Linux also supports the System Use Sharing Protocol records specified by the Rock Ridge Interchange Protocol. They are used to further describe the files in the
171
iso9660 filesystem to a UNIX host, and provide information such as long filenames, UID/ GID, POSIX permissions, and devices. It is automatically recognized within the iso9660 filesystem support under Linux. hpfs
It is the High Performance filesystem, used in OS/2. This filesystem is read-only under Linux due to the lack of available documentation. sysv
It is an implementation of the System V / Coherent filesystem for Linux. It implements all of Xenix FS, System V / 386 FS, and Coherent FS. nfs
It is the network filesystem used to access disks located on remote computers. smb
It is a network filesystem that supports the SMB protocol, used by MS Windows for Workgroups, Windows NT, and Lan Manager. To use smb fs, you need a special mount program. Standard linux command smbmount will do. ncpfs
It is a network filesystem that supports the NCP protocol, used by Novell NetWare. devpts
It is a pseudo file system, traditionally mounted on /dev/pts. In order to acquire a pseudo terminal, a process opens /dev/ptmx; the number of the pseudo terminal is then made available to the process and the pseudo terminal slave can be accessed as /dev/pts/<number>. fat
It is not a separate filesystem, but a common part of the msdos, umsdos and vfat filesystems. UFS
It is a special partition type used for swapping data from memory to hard drive. raiserfs
It is a brand new journalizing filesystem available as standard with Linux kernel version 2.4.1 up.
172
hfs
(=hierarchical files system)MacIntosh filesystem. It is a late beta version., i.e., not recommended for use with critical data, unless read-only. ntfs
MS Windows NT filesytem. It is still experimental under Linux, i.e. not recommended for production machines, unless read-only.
Check if you can contact another machine (give the machines name or IP), press <Ctrl>C when done (without <Ctrl>c, the command keeps going). As all Linux commands, ping has options, including the ping of death attack, when it seems you can ping some servers so they dietry the options -f and -s. host host_to_find, nslookup host_to_find, dig ip_to_find
(Three commands, use any.) Query your default domain name server (DNS) for an Internet name (or IP number) host_to_find. This way you can check if your DNS works. You can also find out the name of the host of which you only know the IP number. traceroute host_to_trace
Have a look how your messages trace to host_to_trace (which is either a host name or IP number). mtr host_to_trace
(as root) A powerful and nice tool that combines the functionality of the older ping and traceroute. firewall-config (as root, in Xterm). A GUI for building your custom firewall. ifconfig
(as root) Display info on the network interfaces currently active (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1, etc, first ppp over modem as ppp0, second as ppp1, etc. The lo is the loopback only interface which should be always active. Use the options (see ifconfig help) to configure the interfaces.
173
ifup interface_name
(/sbin/ifup to run as a user) Startup a network interface. Example: ifup eth0, ifup ppp0, ifup ppp1 Users can start up or shutdown the ppp interface only when the permission is given in the ppp setup (using netconf ). To start a ppp interface (dial-up connection), We normally use kppp available under the KDE K menu (or by typing kppp in an X-terminal). /etc/rc.d/init.d/network restart
Restart the network using its normal initialization script (the same which is used during bootup). Useful if you just have manually made changes to your network configuration. Any other service listed in init.d can be stopped, started, or restarted in a similar way (call the script with an options stop, start or restart). ifdown interface_name (/sbin/ifdown to run it as a user). Shut down the network interface. Example: ifdown ppp0. netstat | more
(as root, in X windows if you wish the nice gtk-based interface). Network diagnostic tool combining the capabilities of traceroute and ping. nmap ip_number
Map the ports on the machine with ip_number. REALLY useful to establish the security of your network configuration as you can see the opened ports. ethereal
(as root, in Xterminal) Network analyzerview the network trafic going through your computer. tcpdump -i ppp0 -a -x
(as root) Print all the network traffic going through the first over-the-phone interface (ppp0) as ascii and hexadecimal.
The process of installing Red Hat Linux is straightforward, although there are lots of little problems scattered throughout the process that can cause hassles. Red Hat Linux is much easier to install than many other versions of Linux, so you will find the installation goes quite easily. Common errors that you might make are handled nicely by the Red Hat installation program, and the system is versatile enough to handle most configuration requirements. The essential steps for installing Red Hat Linux are as follows: 1. Create boot and root disks. 2. Boot Linux from floppies. 3. Partition the hard disk. 4. Create a swap file. 5. Create a Linux file system. 6. Install the Linux software. 7. Configure the kernel. 8. Set the boot process. 9. Reboot into Linux from your hard disk.
The process is similar whether you are installing from a CD-ROM or from a diskette. Because the CD-ROM is the most common form of installation, it is used as the example in this chapter. Much of this chapter will be familiar to you if you have installed Linux before, although some users really dont know what goes on during the automated installation script. Knowing the process, and staying on top of it, helps prevent problems with the Linux installation.
175
Try installing updation packages for the system you have installed. The student has to concentrate for Creation of an Installation Diskette, Partitioning Hard Drive(s) and choosing Desired Packages required to Install, Multi-boot with Other Operating Systems. Give an example of space works of partitions for installing Linux and windows operating systems in one hard disk size of 4.3 Gb. You may use 2 Gb for windows 98 operating system. Install first on a separate hard disk (min 300 MB) Linux OS in text mode only. Install the linux OS including X windows on a separate hard disk (min 1.2 GB). Install the linux OS including X windows on a hard disk (min 4.3 GB) with multi-boot concept along with windows 95/98 also windows NT. Try out creation of Linux boot diskette with different commands. Partition a hard disk with different sizes using any partition command such as diskdruid or fdisk.
II. Choose the correct answer 1. Creation of linux boot disk can be done through
a. rawrite 2. b. mkbootdisk c. diskcopy d. all of these.
The example of a compressed file used for any package installation is a. *.tar.gz b. *.rpm c. *.zip d. all of these.
3.
Linuxconf can be used to a. mount a drive b. configure a network c. administer users d. all of these
4.
LILO is used for a. Creation of boot diskette b. Managing linux network c. Multiboot d. Linux configuration
5.
A Linux system must contain a. Swap partition b. root password c. linux native partition d. all of these
6.
Setup command helps to configure a. Only X windows b. Mouse c. Sound card d. all of these
176
III. Say True or False 1. Linear mode option must be used for multi boot option with size of first partition more than 1023 cylinders.
2. Formatting of all the partitions or mount points is a must for Linux installation
3. /dev mount point contains all user files and information. 4. fdisk command is used to create boot diskette. 4. Windows NT operating system can not be installed as dual boot for linux.
IV. Essay type questions 1. Explain how to create an installation or boot diskette.
2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. Illustrate the significance of /etc/fstab file with respect to installation. Elucidate the different types of partition sizes required for linux installation. What is partitioning of hard disk drive? Why it is important explain. Describe the possible benefits of partitioning of hard disk drive. Describe the network administration tools and commands with options. Explain the usage of /, swap, /home, /usr mount points with respect to linux installation. What is LILO? How it is useful in Linux. Enumerate the full hardware details of a computer involving all parts. Explain how the updations of packages can be done in Linux. Brief the function of the command linuxconf. What is a tar file? Explain its options in detail. What is a rpm utility? Explain its options in detail. Explain the Partitioning utility fdisk in detail with its different options. Describe the standard linux filesystem types with its significance. Write a detail note on Linux installation.
177
V. Further readings and other activities Get more information using man or info or any help command for linuxconf, fs, lilo, setup, Xconfigurator, fdisk, sndconfig, mouseconfig, netconf, neconfig, userconf, ipcalc, fstab, disk, sfdisk, tar, rpm. EX: 1. $ man sfdisk 2. $ apropos nysysv 3. info mtools
For further readings you can refer the following books 1. Title: Linux internals Auihors: M.V.Panduranga Rao and K.Roopa, JNNCE, Shimoga http://www.pandurangarao.i8.com/doc/linux/linuxbook.html http://www.raomvp.bravepages.com/doc/linux/linuxbook.html http://www.geocities.com/raomvp/doc/linux/linuxbook.html A complete reference for you to get more information. Title: The Complete Reference Linux Foutth Edition Author: Richard Petersen Publication: Tata McGraw-Hill Title: Red Hat Linux Starter kit in 24 hours Author: Judith Samson etal Publication: Sams Techmedia Title: Unix Shell Programming Author: Yashawant Kanitkar Publication: BPB Title: Linux Kernel Internals Author: M. Beck etal Publication: Addison-Wesley, Second Edition Title: Unix Power Tools Author: Jerry Peek etal Publication: BPB Title: Unix System Programming Author: Richard Stevens Title: Linux System Administration Handbook - for detail information on problems of linux installation.
2.
3.
4.
5.
6.
7. 8.
178
VI. Solutions I. Choose the correct answer 1.d 2.d 3.d 4.c
5.d 6.d
Chapter 10
Glossary
GLOSSARY OF TERMS
$HOME Environment variable that points to your login directory. $PATH The shell environment variable that contains a set of directories to be searched for LINUX commands. /dev/null file The place to send output that you are not interesting in seeing; also the place to get input from when you have none (but the program or command requires something). This is also known as the bit bucket, which is where old bits go to die. /etc/cshrc file The file containing shell environment characteristics common to all users that use the C Shell. /etc/group file This file contains information about groups, the users they contain, and passwords required for access by other users. The password may actually be in another filethe shadow group fileto protect it from attacks. /etc/inittab file The file that contains a list of active terminal ports for which LINUX will issue the login prompt. This also contains a list of background processes for LINUX to initialize. Some versions of LINUX use other files like /etc/tty.
179
180
/etc/motd file
Chapter 10 - Glossary
Message Of The Day file usually contains information the system administrator feels is important for you to know. This file is displayed when the user signs on the system. /etc/passwd file Contains user information and password. The password may actually be in another filethe shadow password fileto protect it from attacks. /etc/profile The file containing shell environment characteristics common to all users that use the Bourne and Korn shells. abbreviation (vi) User-defined character sequences that are expanded into the defined text string when typed during insert mode. absolute pathname The means used to represent the location of a file in a directory by specifying the exact location including all directories in the chain including the root. API (Application Program Interface) The specific method prescribed by a computer operating system, application, or third-party tool by which a programmer writing an application program can make requests of the operating system. arguments See parameters. ARPA See DARPA. ASCII (American Standard Code for Information Interchange) Used to represent characters in memory for most computers. AT&T UNIX Original version of UNIX developed at AT&T Bell Labs, which was later known as UNIX Systems Laboratories. Many current versions of UNIX are descendants; even BSD UNIX was derived from early AT&T UNIX.
181
attribute The means of describing objects. The attributes for a ball might be: rubber, red, 3 cm in diameter. The behavior of the ball might be how high it bounces when thrown. Attribute is another name for the data contained within an object (class). AWK Programming language developed by A.V. Aho, P.J. Weinberger, and Brian W. Kernighan. The language is built on C syntax, includes the regular expression search facilities of grep, and adds in the advanced string and array handling features that are missing from the C language. nawk, gawk, and POSIX awk are versions of this language. background Processes usually running at a lower priority and with their input disconnected from the interactive session. Any input and output are usually directed to a file or other process. background process An autonomous process that runs under LINUX without requiring user interaction. backup The process of storing the LINUX system, applications, and data files on removable media for future retrieval. bash BASH stands for GNU Bourne Again Shell, and is based on the Bourne shell, sh, the original command interpreter. beep Usually referred to in LINUX documentation as the bell (see bell). bell The character sent by a program to a terminal to indicate some kind of error condition; for example, in vi pressing Esc to exit insert mode when you are already in command mode; actually the ^G character which rather than displaying on the terminal instead causes it to sound an alarm, which on ancient teletype terminals was implemented as a bell. Different terminals produce different sounds for their bells including one old video terminal that sounded like someone shifting gears without benefit of clutch. binding (emacs) The assignment of a shift-key sequence to an Emacs editing command.
182
block-special
Chapter 10 - Glossary
A device file that is used to communicate with a block oriented I/O device. Disk and tape drives are examples of block devices. The block-special file refers to the entire device. You should not use this file unless you want to ignore the directory structure of the device (that is, if you are coding a device driver). boot or boot up The process of starting the operating system (LINUX). Bourne Shell The original standard user interface to UNIX that supported limited programming capability. BSD UNIX Version of UNIX developed by Berkeley Software Distribution and written at UC Berkeley buffer (vi) The working version of the file you are editing is usually called the buffer; the buffer is actually an image of the file kept in random access memory during editing; changes are made in this image and only written out to disk upon user command (or when the vi autowrite setting is in effect); see also named buffer and undo buffer. buffer list (emacs) A special window which shows all of the buffers currently open; allows you to manipulate buffers using buffer list commands. C Programming language developed by Brian W. Kernighan and Dennis M. Ritchie. The C language is highly portable and available on many platforms including mainframes, PCs, and, of course, UNIX systems. C Shell A user interface for UNIX written by Bill Joy at Berkeley. It also features C programming-like syntax. CD-ROM (Compact Disk-Read Only Memory) Computer-readable data stored on the same physical form as a musical CD. Large capacity, inexpensive, slower than a hard disk, and limited to reading. There are versions that are writable (CD-R, CD Recordable) and other formats that can be written to once or many times. CGI (Common Gateway Interface) A means of transmitting data between Web pages and programs or scripts executing on the server. Those programs can then process the data and send the results back to the users browser through dynamically creating HTML.
183
character-special A device file that is used to communicate with character-oriented I/O devices such as terminals, printers, or network communications lines. All I/O access is treated as a series of bytes (characters). characters 1. alphabetic The letters A through Z and a through z. 2. alphanumeric The letters A through Z and a through z, and the numbers 0 through 9. 3. control
Any non-printable characters. The characters are used to control devices, separate records, and eject pages on printers. 4. numeric The numbers 0 through 9. 5. special
Any of the punctuation characters or printable characters that are not alphanumeric. Include the space, comma, period, and many others. child-process See sub-process. child-shell See sub-shell. class A model of objects that have attributes (data) and behavior (code or functions). It is also viewed as a collection of objects in their abstracted form. command line (1) The shell command line from which the current vi or Emacs session was started; (2) the ex command line, where ex commands are entered. command line editing LINUX shells support the ability to recall a previously entered command, modify it, and then execute the new version. The command history can remain between sessions (the commands you did yesterday can be available for you when you log in today). Some shells support a command line editing mode that uses a subset of the vi, emacs, or gmacs editor commands for command recall and modification.
184
command line history See command line editing. command line parameters
Chapter 10 - Glossary
Used to specify parameters to pass to the execute program or procedure. Also known as command line arguments. command prompt See shell prompt. completion (emacs) The automatic provision of the rest of a command or a file name; when the command or file name cannot be resolved to a single entity, a menu of choices is provided (type a few characters of the name and press TAB; Emacs will either complete the name or give you a menu of choices). configuration files Collections of information used to initialize and set up the environment for specific commands and programs. Shell configuration files set up the users environment. configuration files, shell For Bourne shell: /etc/profile and $HOME/.profile. For Korn shell: /etc/profile, $HOME/.profile, and ENV= file. For C shell: /etc/.login, /etc/cshrc, $HOME/.login, $HOME/.cshrc, and $HOME/.logout. Older versions may not support the first two files listed. For BASH: /etc/profile/, $HOME/.bash_profile, $HOME/.bash_login, $HOME/.profile, $HOME/ .bashrc, ~/.bash_logout. control keys These are keys that cause some function to be performed instead of displaying a character. These functions have names, for instance, the end-of-file key tells the LINUX that there is no more input. The typical end-of-file key is the <^D> (control-d) key. CPU (Central Processing Unit) The primary brain of the computer; the calculation engine and logic controller. current macro (emacs) The most recently recorded macro; it is executed by the call-last-kbd-macro function.
185
cursor The specific point on the screen where the next editing action will take place; the cursor is usually indicated on the screen by some sort of highlighting, such as a underscore or a solid block, which may or may not be blinking. daemon A system related background process that often runs with the permissions of root and services requests from other processes. DARPA (U.S. Department of Defense Advanced Research Projects Agency) Funded development of TCP/IP and ARPAnet (predecessor of the Internet). database server See server, database. default settings Most tools and systems are governed by a number of settings; those that are in effect when the tool is started is known as the default. vi is governed by a number of settings; the default settings are those in effect when vi is first started and no automatic overrides of settings are in effect through .exrc files or EXINIT environment variables. device file File used to implement access to a physical device. This provides a consistent approach to access of storage media under LINUXdata files and devices (such as tapes and communication facilities) are implemented as files. To the programmer, there is no real difference. directory A means of organizing and collecting files together. The directory itself is a file that consists of a list of files contained within it. The root (/) directory is the top level and every other directory is contained in it (directly or indirectly). A directory might contain other directories, which are known as sub-directories. directory navigation The process of moving through directories is known as navigation. Your current directory is known as the current working directory. Your login directory is known as the default or home directory. Using the cd command, you can move up and down through the tree structure of directories. DNS (Domain Name Server) Used to convert the name of a machine on the Internet (name.domain.com) to the numeric address (123.45.111.123).
186
DOS (Disk Operating System)
Chapter 10 - Glossary
Operating system that is based on the use of disks for the storage of commands. It is also a generic name for MS-DOS and PC-DOS on the Personal Computer. MS-DOS is the version Microsoft sells and PC-DOS is the version IBM sells. Both are based on Microsoft code. EBCDIC (Extended Binary Coded Decimal Interchange Code) The code used to represent characters in memory for mainframe computers. echo The display on the screen of characters you type is sometimes called the echo of characters; it is called this because usually your terminal is set up not to display the characters directly as typed, but rather to wait for them to be sent to the computer, which then echoes (sends) them back to your terminal. ed A common tool used for line-oriented text editing. e-mail Messages sent through an electronic medium instead of through the local postal service. There are many proprietary e-mail systems that are designed to handle mail within a LAN environment; most of these are also able to send over the Internet. Most Internet (open) e-mail systems make use of MIME to handle attached data (which can be binary). emacs A freely available editor now part of the GNU software distribution. Originally written by Richard M. Stallman at MIT in the late 1970s, it is available for many platforms. It is extremely extensible and has its own programming language; the name stands for Editing with MACroS.encapsulation. The process of combining data (attributes) and functions (behavior in the form of code) into an object. The data and functions are closely coupled within an object. Instead of every programmer being able to access the data in a structure his own way, programmers have to use the code connected with that data. This promotes code reuse and standardized methods of working with the data. environment variables See variables, environmental. escape (1) (vi) The Esc key, used to terminate insert mode, or an incomplete vi command; (2) To prevent a character from having its normal interpretation by a program by preceding it with the escape character (usually \, the backslash); for example in a regular expression, to search for a literal character that has a special meaning in a regular expression, it must be escaped; as a specific example, to search for a period
187
(.), you must type it escaped as \. ethernet A networking method where the systems are connected to a single shared bus and all traffic is available to every machine. The data packets contain an identifier of the recipient, which is the only machine that should process that packet. expression A constant, variable, or operands and operators combined. Used to set a value, perform a calculation, or set the pattern for a comparison (regular expressions). fifo First In, First Out. See named pipe. file Collection of bytes stored on a device (typically a disk or tape). Can be source code, executable binaries or scripts, or data. 1. indexed
A file based on a file structure where data can be retrieved based on specific keys (name, employee number, and so on) or sequentially. The keys are stored in an index. This is not directly supported by the LINUX operating system; usually implemented by the programmer or by using tools from an ISV. A typical form is known as ISAM. 2. line sequential
a. A file that can only be accessed sequentially (not randomly). b. A file without record separators. Typically fixed length but LINUX does not know what that length is and does not care. 4. text
A file with record separators. May be fixed or variable length; LINUX tools can handle these files because it can tell when the record ends (by the separator). file compression The process of applying mathematical formula to data typically resulting in a form of the data that
188
Chapter 10 - Glossary
occupies less space. A compressed file can be uncompressed (lossless) resulting in the original file. When the compression/uncompress process results in exactly the same file as was originally compressed, it is known as lossless. If information about the original file is lost, the compression method is know as lossy. Data and programs need lossless compression; images and sounds can stand lossy compression. filename The name used to identify a collection of data (a file). Without a pathname, it is assumed to be in the current directory. filename generation The process of the shell interpreting meta-characters (wild cards) to produce a list of matching files. This is referred to as filename expansion or globbing. filename, fully qualified The name used to identify a collection of data (a file) and its location. It includes both the path and name of the file; typically, the pathname is fully specified (absolute). See also pathname and pathname, absolute. filesystem A collection of disk storage that is connected (mounted) to the directory structure at some point (sometimes at the root). Filesystems are stored in a disk partition and are also referred to as disk partitions. firewall A system used to provide a controlled entry point to the internal network from the outside (usually the Internet). This is used to prevent outside or unauthorized systems from accessing systems on your internal network. The capability depends on the individual software package, but the features typically include: filter packets, filter datagrams, provide system (name or IP address) aliasing, and rejecting packets from certain IP addresses. It can also prevent internal systems from accessing the Internet on the outside. In theory, it provides protection from malicious programs or people on the outside. The name comes from the physical barrier between connected buildings or within a single building that is supposed to prevent fire from spreading from one to another. flags See options. foreground Programs running while connected to the interactive session. fseek
189
Internal function used by LINUX to locate data inside a file or filesystem. ANSI standard fseek accepts a parameter that can hold a value of +2 to -2 billion. This function, used by the operating system, system tools, and application programs, is the cause of the 2 GB file and filesystem size limitation on most systems. With 64 bit operating systems, this limit is going away. FTP (File Transfer Protocol, or File Transfer Program) A system-independent means of transferring files between systems connected via TCP/IP. Ensures that the file is transferred correctly, even if there are errors during transmission. Can usually handle character set conversions (ASCII/EBCDIC) and record terminator resolution (<lf> for LINUX, <cr> and <lf> for MS/PC-DOS). gateway A combination of hardware, software, and network connections that provides a link between one architecture and another. Typically, a gateway is used to connect a LAN or LINUX server with a mainframe (that uses SNA for networking resulting in the name: SNA gateway). A gateway can also be the connection between the internal and external network (often referred to as a firewall). See also firewall. globbing See filename generation. GNU GNU stands for GNUs Not Unix, and is the name of free useful software packages commonly found in UNIX environments that are being distributed by the GNU project at MIT, largely through the efforts of Richard Stallman. grep A common tool used to search a file for a pattern. egrep and fgrep are newer versions. Egrep allows the use of extended (hence the e prefix) regular expressions, fgrep uses limited expressions for a faster (hence the f prefix) searches. here document The << redirection operator, known as here document, allows keyboard input (stdin) for the program to be included in the script. HTML (HyperText Markup Language) Describes World Wide Web pages. It is the document language that is used to define the pages available on the Internet through the use of tags. A browser interprets the HTML to display the desired information.
190
i-node
Chapter 10 - Glossary
Used to describes a file and its storage. The directory contains a cross reference between the i-node and pathname/filename combination. Also known as inode. I-Phone (Internet Phone) A method of transmitting speech long distances over the Internet in near real-time allowing the participants to avoid paying long distance telephone charges. They still pay for the call to their ISP and the ISPs service charges. ICMP (Internet Control Message Protocol) Part of TCP/IP that provides network layer management and control. inheritance A method of object-oriented software reuse in which new classes are developed based on existing ones by using the existing attributes and behavior and adding on to them. For example, if the base object is automobile with attributes of an engine, four wheels, and tires, and behavior of acceleration, turning, and deceleration, then a sports car would modify the attributes so the engine would be larger or have more horsepower than the default, the four wheels would include alloy wheels and high speed rated tires, and the behavior would also be modified for faster acceleration, tighter turning radius, and faster deceleration. inode See i-node. Internet A collection of different networks that provide the ability to move data between them. It is built on the TCP/IP communications protocol. Originally developed by DARPA, it was taken over by NSF, and has now been released from governmental control. Internet Service Provider The people who connect you to the Internet. IRC (Internet Relay Chat) A server-based application that allows groups of people to communicate simultaneously through textbased conversations. IRC is similar to Citizen Band radio or the chat rooms on some bulletin boards. Some chats can be private (between invited people only) or public (where anyone can join in). IRC now also supports sound files as well as text it can also be useful for file exchange.
191
ISAM (Indexed Sequential Access Method) On LINUX and other systems, ISAM refers to a method for accessing data in a keyed or sequential way. The LINUX operating system does not directly support ISAM files; they are typically add on products. ISP See Internet Service Provider. ISV (Independent Software Vendor) Generic name for software vendors other than your hardware vendor. kernel The core of the operating system that handles tasks such as memory allocation, device input and output, process allocation, security, and user access. LINUX tends to have a small kernel when compared to other operating systems. keyboard macros A feature which allows a special key sequence to stand for another, usually more complex sequence; in vi, keyboard macros are implemented via the :map command. kill ring (emacs) A set of buffers where killed text is kept; the buffers are arranged in a circular pattern. When commands that automatically move from one buffer to the next get to the end of the set, the next movement will be to the first buffer in the ring. Korn Shell A user interface for LINUX with extensive scripting (programming) support. Written by David G. Korn. The shell features command line editing and will also accept scripts written for the Bourne Shell. LAN (Local Area Network) A collection of networking hardware, software, desktop computers, servers, and hosts all connected together within a defined local area. A LAN could be an entire college campus. limits See quota. line address (vi and ex) The way a selected set of lines is indicated in ex mode is through a line address. A line address can be an absolute line number, relative line number, or special symbols which refer to the beginning or of the file.
192
link 1. hard
Chapter 10 - Glossary
Directory entry that provides an alias to another file that is in the same filesystem. Multiple entries appear in the directory (or other directories) for one physical file without replication of the contents. 2. soft
Directory entry that provides an alias to another file that can be in another filesystem. Multiple entries appear in the directory for one physical file without replication of the contents. Implemented through link files; see also link file. 4. file
File used to implement a symbolic link producing an alias on one filesystem for a file on another. The file only contains the fully qualified filename of the original (linked-to) file. lisp A programming language used in artificial intelligence. The name stands for LISt Processing. It is the programming language that Emacs is written in and also refers to three major modes within it. literal text string An exact character text string, with no wildcards. login The process that a user gains access to a LINUX system. This can also refer to the user id that is typed at the login prompt. macro A recorded series of keystrokes which can be played back to accomplish the same task repetitively. major mode (emacs) A named set of behavioral characteristics; a buffer can be in only one major mode at a time. For examples, text mode for writing a letter; c mode for writing c source code. man page On-line reference tool under LINUX that contains the documentation for the systemthe actual pages from the printed manuals. It is stored in a searchable form for improved capability to locate information.
193
manual page See man page. mappings (vi) User-defined character sequences (which may include control keys) that are interpreted as a command sequence (which may also include control keys). memory 1. real The amount of storage that is being used within the system (silicon; it used to be magnetic cores). 2. virtual Memory that exists but you cannot see. Secondary storage (disk) is used to allow the operating system to allow programs to use more memory than is physically available. Part of a disk is used as a paging file and portions of programs and their data are moved between it and real memory. To the program, it is in real memory. The hardware and operating system performs translation between the memory address the program thinks it is using the where it is actually stored. meta-character A printing character that has special meaning to the shell or another command. It is converted into something else by the shell or command - the asterisk <*> is converted by the shell to a list of all files in the current directory. MIME (Multipurpose Internet Mail Extensions) A set of protocols or methods of attaching binary data (executable programs, images, sound files, and so on) or additional text to e-mail messages. mini-buffer (emacs) The last line on the screen, where commands are entered. minor mode (emacs) A particular characteristic which can be independently toggled on or off. For example, autofill mode for easing the creation of document text. mode Many programs offer only subsets of their functions at any given time, because only certain functions are relevant within an immediate context; further, the same keystroke may invoke different commands in these different contexts; such a context is referred to as a mode. Major modes in vi are insert mode (for adding new text into the buffer), and command mode (for most other editing actions).
194
MPTN (MultiProtocol Transport Network) IBM networking protocol to connect mainframe to TCP/IP network. named buffer
Chapter 10 - Glossary
(vi)A memory location where text objects can be stored during a single vi session; named buffers persist when you switch from one file to another during a session and are the primary way of moving and copying text between files. named pipe An expanded function of a regular pipe (redirecting the output of one program to become the input of another). Instead of connecting stdout to stdin, the output of one program is sent to the named pipe and another program reads data from the same file. This is implemented through a special file known as a pipe file or fifo. The operating system ensures the proper sequencing of the data. Little or no data is actually stored in the pipe file; it just acts as a connection between the two. Netnews This is a loosely controlled collection of discussion groups. A message (similar to an e-mail) is posted in a specific area and then people can comment on it, publicly replying to the same place (posting a response) for others to see. A collection of messages along the same theme is referred to as a thread. Some of the groups are moderated, which means that nothing is posted without the approval of the owner. Most are not and the title of the group is no guarantee that the discussion will be related. The official term for this is Usenet News. NFS (Network File System) Means of connecting disks that are mounted to a remote system to the local system as if they were physically connected. NIS (Network Information Service) A service that provides information necessary to all machines on a network, such as NFS support for hosts and clients, password verification, and so on. NNTP (Net News Transport Protocol) Used to transmit Netnews or usenet messages over top of TCP/IP. See Netnews for more information on the messages transmitted. null statement A program step that performs no operation but to hold space and fulfill syntactical requirements of the programming language. Also known as a NO-OP for no-operation performed.
195
numeric setting A setting which takes a numeric value, rather than an enabled or disabled state. Applies to many tools including vi and the different shells. object An object in the truest sense of the word is something that has physical properties, such as automobiles, rubber balls, and clouds. These things have attributes and behavior. They can be abstracted into data (attribute) and code (behavior). Instead of just writing functions to work on data, they are encapsulated into a package that is known as an object. open mode The visual mode of the ex editor. operator Meta-character that performs a function on values or variables. The plus sign <+> is an operator that adds two integers. options Program- or command-specific indicators that control behavior of that program. Sometimes called flags. The -a option to the ls command shows the files that begin with a . (such as .profile, .kshrc, and so on.) Without it, these files would not be shown, no matter what wildcards were used. These are used on the command line. See also parameters. package (emacs) A feature set which can be added to the editor. Major modes and many functions are implemented via packages. Numerous packages are built in to standard Emacs; many others are freely or otherwise available. parameters Data passed to a command or program through the command line. These can be options (see options) that control the command or arguments that the command works on. Some have special meaning based on their position on the command line. parent process identifier Shown in the heading of the ps command as PPID. The process identifier of the parent-process. See also parent-process. parent-process Process that controls another often referred to as the child- or sub-process. See process.
196
parent-shell
Chapter 10 - Glossary
Shell (typically the login shell) that controls another, often referred to as the child- or sub-shell. See shell. password The secure code that is used in combination with a user id to gain access to a LINUX system. pathname The means used to represent the location of a file in the directory structure. If you do not specify a pathname, it defaults to the current directory. Also see absolute pathname and relative pathname. PDP (Personal Data Processor) Computers manufactured by Digital Equipment Corporation. LINUX was originally written for a PDP7 and gained popularity on the PDP-11. The entire series were inexpensive mini-computers popular with educational institutions and small businesses. Perl (Practical Extraction and Report Language) Programming language developed by Larry Wall. (Perl stands for Practical Extraction and Report Language or Pathologically Eclectic Rubbish Language, both are equally valid). The language provides all of the capabilities of awk and sed, plus many of the features of the shells and C. permissions When applied to files, they are the attributes that control access to a file. There are three levels of access: owner (the file creator), group (people belonging to a related group as determined by the system administrator), and other (everyone else). The permissions may be r for read, w for write, and x for execute. The execute permissions flag is also used to control who may search a directory. pipe A method of sending the output of one program (redirecting) to become the input of another. The pipe character <|> tells the shell to perform the redirection. pipe file See named pipe. polymorphism Allows code to be written in a general fashion to handle existing and future related classes. Properly developed, the same behavior can act differently depending on the derived object it acts on. With an automobile, the acceleration behavior might be different for a station wagon and a dragster which are
197
subclasses of the superclass automobile. The function would still be accelerate(), but the version would vary (this may sound confusing, but the compiler keeps track and figures it all out). POSIX POSIX stands for Portable Operating System Interface, UNIX. It is the name for a family of open system standards based on UNIX. The name has been credited to Richard Stallman. The POSIX Shell and Utilities standard developed by IEEE Working Group 1003.2 (POSIX.2) concentrates on the command interpreter interface and utility programs. PPP (Point-to-Point Protocol) Internet protocol over serial link (modem). process A discrete running program under LINUX. The users interactive session is a process. A process can invoke (run) and control another program that is then referred to as a sub-process. Ultimately, everything a user does is a subprocess of the operating system. process identifier Shown in the heading of the ps command as PID. The unique number assigned to every process running in the system. quota General description of a system-imposed limitation on a user or process. It can apply to disk space, memory usage, CPU usage, maximum number of open files, and many other resources. quoting The use of single and double quotes to negate the normal command interpretation and concatenate all words and whitespace within the quotes as a single piece of text. range (vi, ed, and ex) a line address which indicates one or more lines from a starting line to an ending line; indicated as start,end where both start and end are individual line addresses. recursive edit (emacs) A feature that allows a query-replace operation to be temporarily suspended while other editing is done. redirection The process of directing a data flow from the default. Input can be redirected to get data from a file or
198
Chapter 10 - Glossary
the output of another program. Normal output can be sent to another program or a file. Errors can be sent to another program or a file. regular expression A way of specifying and matching strings for shells (filename wildcarding), grep (file searches), sed, and awk. relative pathname The means used to represent the location of a file in a directory other than the current by navigating up and down through other directories using the current directory as a base. reserved word A set of characters recognized by LINUX and related to a specific program, function, or command. RFC (Request For Comment) Document used for creation of Internet and TCP/IP related standards. rlogin (Remote Login) Gives the same functionality of telnet, with the added functionality of not requiring a password from trusted clients, which can also create security concerns. See telnet. root 1) The user who owns the operating system and controls the computer. 2) The processes of the operating system run as though a user, root, signed on and started them. The root user is all powerful and can do anything he or she wants. For this reason, the root user is often referred to as a super-user. It is also the very top of the directory tree structure. routing The process of moving network traffic between two different physical networks; also decides which path to take when there are multiple connections between the two machines. It may also send traffic around transmission interruptions. RPC (Remote Procedural Call) Provides the capability to call functions or subroutines that run on a remote system from the local one. scripts A program written for a LINUX utility including shells, AWK, perl, sed, and others. Also see shell scripts.
199
sed A common tool used for stream text editing, having ed-like syntax. server, database A system designated to run database software (typically a relational database like Oracle, SQL Server, Sybase, or others). Other systems connect to this one to get the data (client applications). settings vi is governed by a number of internal variable called settings; these control how certain actions take place. Shell The part of LINUX that handles user input and invokes other programs to run commands. Includes a programming language. See also Bourne Shell, C Shell, Korn Shell, tcsh, and BASH. shell environment The shell program (Bourne, Korn, C, tcsh, or BASH), invocation options, and preset variables that define the characteristics, features and functionality of the LINUX command line and program execution interface. shell buffer (emacs) A buffer in which an interactive LINUX shell session has been started. shell scripts A program written using a shell programming language like those supported by Bourne, Korn, or C shells. shift-key sequence (emacs) To perform a shift-key sequence, hold down the designated shift key (for example, Shift, Ctrl, Alt, or Meta), then press the second designated key, then release both keys. When typing several consecutive shift-key sequences that use the same shift key, you can keep holding down the shift key for the duration. signal A special flag or interrupts that is used to communicate special events to programs by the operating system and other programs. SLIP (Serial Line Internet Protocol)
200
Chapter 10 - Glossary
Internet over a serial link (modem). The protocol frames and controls the transmission of TCP/IP packets of the line. SNA(System Network Architecture) IBM networking architecture. special keys See control keys. stderr The normal error output for a program that is sent to the screen by default. Can be redirected to a file. stdin The normal input for a program, taken from the keyboard by default. Can be redirected to get input from a file or the output of another program. stdout The normal output for a program that is sent to the screen by default. Can be redirected to a file or to the input of another program. sticky bit One of the status flags on a file that tells LINUX to load a copy of the file into the page file the first time it is executed. This is done for programs that are commonly used so the bytes are available quickly. When the sticky bit is used on frequently used directories, they are cached in memory. stream A sequential collection of data. All files are streams to the LINUX operating system. To it, there is no structure to a filethat is something imposed by application programs or special tools (ISAM packages or relational databases). sub-directory See directory. sub-process Process running under the control of another, often referred to as the parent-process. See process. sub-shell Shell running under the control of another, often referred to as the parent-shell (typically the login shell). See shell.
201
subnet A portion of a network that shares a common IP address component. Used for security and performance reasons. super-user See root. system administrator The person who takes care of the operating system and user administrative issues on LINUX systems. Also called a system manager although that term is much more common in DEC VAX installations. system manager See system administrator. system programmer See system administrator. TCP/IP (Transport Control Protocol/Internet Protocol) The pair of protocols and also generic name for suite of tools and protocols. that forms the basis for the Internet. Originally developed to connect systems to the ARPANET. tcsh A C shell-like user interface featuring command-line editing. Telnet Protocol for interactive (character user interface) terminal access to remote systems. The terminal emulator that uses the telnet protocol is often known as telnet or tnvt100. Terminal A hardware device, normally containing a cathode ray tube (screen) and keyboard for human interaction with a computer system. text object (vi) A text object is the portion of text in the buffer that would be traversed by a specific movement command; for example w refers to the next small word. text processing languages A way of developing documents in text editors with embedded commands that handle formatting. The
202
Chapter 10 - Glossary
file is fed through a processor that executes the embedded commands producing a formatted document. These include roff, nroff, troff, RUNOFF, TeX, LaTeX, and even the mainframe SCRIPT. TFTP (Trivial File Transfer Protocol or Trivial File Transfer Program) A system-independent means of transferring files between systems connected via TCP/IP. It is different from FTP in that it does not ensure that the file is transferred correctly, does not authenticate users, and is missing a lot of functionality (like the ls command). toggle A mode that is alternately turned on and off by successive entry of its command. toggle setting (vi) A setting which is either enabled or disabled; for example, for the fictitious setting named option, you would enable the setting by entering the command :set option; you would disable the setting by entering the command :set nooption. top A common tool used to display information about the top processes on the system. typewriter key The subset of a terminal keyboard that is on a standard typewriter; generally the alphanumeric keys, but not the function, cursor control, or numeric pad keys. UDP (User Datagram Protocol) Part of TCP/IP used for control messages and data transmission where the delivery acknowledgment is not needed. The application program must ensure data transmission in this case. undo buffer (vi) A location in memory where the most recent deleted text object is saved, either for later undoing of the deletion, or for copying of the object to another location. URL (Uniform Resource Locator) The method of specifying the protocol, format, login (usually omitted), and location of materials on the Internet. Usenet See Netnews. UUCP (UNIX-to-UNIX-Copy-Program)
203
Used to build an early, informal network for the transmission of files, e-mail, and Netnews. variables, attributes The modifiers that set the variable type. A variable can be string or integer, left or right justified, readonly or changeable, and other attributes. variables, environmental A place to store data and values (strings and integers) in the area controlled by the shell so they are available to the current and sub-processes. They can just be local to the current shell or available to a subshell (exported). variables, substitution The process of interpreting an environmental variable to get its value. viewport The portion of the buffer that appears in a window on your screen; one way to think of moving through the buffer is to think of the viewport as sliding back and forth through the buffer. Web See World Wide Web. whitespace Blanks, space and tabs that are normally interpreted to delineate commands and filenames unless quoted. wildcard Means of specifying filename(s) where the operating system determines some of the characters. Multiple files may match and will be available to the tool. window The portion of your screen which is displaying a viewport into a buffer. World Wide Web A collection of servers and services on the Internet that run software that communicate using a common protocol (HTTP). Instead of having to remember the location of these resources, links are provided from one Web page to another through the use of URLs (Uniform Resource Locators). WWW See World Wide Web.
204
X Window System
Chapter 10 - Glossary
A windowing and graphics system developed by MIT, to be used in client/server environments. X See X Window System. X11 See X Window System. X-windows The wrong term for the X Window System. See X Window System.