Linux Section 1 - Introduction                   

   Contact
   Search
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Messages
   Chat
   MCSE
   Linux
   Cabling   
   ActionScript
   Downloads
   E-Cards   
 
    
    
1. Introduction 2. BASH commands 3. Configuration 4. Networking 5. Customizing 6. Scripting

Linux is growing in popularity and use, making certifications like Comptia's Linux+ (a standard in the U.S. Navy) and RedHat's RHCE (Red Hat Certified Engineer) more valuable. With projects like OLPC (One Laptop Per Child), Linux is experiencing exponential growth in educational and government fields and the developing world. This is largely due in part to its price tag - it's free.

Linux is an Intel-friendly operating system platform at the forefront of open source development.  It is based on several different shells of the Unix operating system.  One of the more common command shells is the BASH command shell, called the "Bourne Again Shell" since its predecessor was the "Bourne Shell". The Linux kernel is robust and powerful, and can be run apart from its GUI through the implementation of different run levels.  This means that it is extremely efficient for file, web, FTP, DHCP and DNS server applications that do not require a Graphical User Interface (GUI).  This makes running services (daemons) on a Linux computer less resource intensive and therefore more compatible with legacy hardware. Again, as a footnote, the services we find in Microsoft's OSes are called “daemons” under Linux. The “a” was added to prevent folks from having to say “demon”, which tends to spook people, though some of you network administrators may feel you have battled a few “demons” in your time.  ;-)

One may proceed to run level 5 and load the X Windows graphical interface and utilize rich multimedia and powerful administration and analysis tools. Then, when the CPU cycles and memory required to maintain a graphical interface are no longer required, one may drop down to run level 3 and free a substantial amount of resources while the machine functions as a web server, DHCP server, DNS server, NIS authentication server, proxy server, mail server, FTP server, remote desktop and application server, firewall, router or any combination of these services. In addition to being a network Swiss army knife, so to speak, with all of its daemons and capabilities, Linux makes a robust workstation as well.

Installation: Linux may be installed via CDs/DVDs or from a removable drive. Upon installation, you may choose to have the install routine automatically create a configuration for you, or you may choose to manually configure partitioning yourself under a utility called “Disk Druid”. You will need to specify a swap partition, as Linux uses this in place of the paging file (pagefile.sys) or swap file (i386.swp) of Windows operating systems. Despite the difference in structure, the swap partition is used for the same purpose – virtual memory, when RAM is insufficient. The size of this swap partition should at least be the size of the available RAM, if not greater. You will then need to select a system partition and configure it with the root mount point of “/”. This partition can be formatted as ext2, ext3 or Reiser.

I usually choose ext2 for the greatest amount of multi-boot compatibility. The reasons for this are multi-faceted. Linux must use a kernel re-compile including ntfs-3g to read/write NTFS and VFAT (FAT32/FAT16) partitions. Windows must use “ext2fsd” or “FS-driver” to read/write ext2 and ext3 partitions. In addition, when ghosting partitions for backup, GHOST can reliably back up ext2 partitions with the command switch “ghost –ial”, but has several issues with ext3 or Reiser file systems. The different file systems that Linux can manipulate and their capabilities are as follows:

ext2 = max partition size is 32Tb, max file size is 2Tb, POSIX permissions
ext3 = max partition size is 32Tb, max file size is 2Tb, POSIX permissions

FAT = max partition size is 4Gb, max file size is 2Gb, no permissions
FAT32 = max partition size is 32Gb, max file size is 4Gb, no permissions
NTFS = max partition size is 2TB, max file size is 2TB, ACE/DACL permissions and encryption

You may then install a boot loader, usually GRUB but sometimes LILO. This boot loader gives you the option of booting into Linux or other operating systems on start-up. GRUB’s configuration file, grub.conf, can be modified in /boot/grub and may be compared to the Windows boot loader’s “boot.ini” file in 2003/XP.

Access Control: Unlike a Microsoft ACE/DACL control system, Linux implements a Unix POSIX permissions system. In this system, every file and directory can have a combination of read, write and execute privileges.  These permissions are represented numerically with the values:

4 = read
2 = write
1 = execute

In this way, permission can be assigned to an object by adding the values together with a command called “chmod” or the GUI. In addition, Linux supports group membership and individual ownership, so that you can add users to multiple groups and then assign permission to those groups. The order in which these values are represented are:

User Rights  +  Group Rights  + Other

“Other” can be compared to Microsoft’s “everyone” account. It refers to anyone who is not specified by the group or user categories. Examples would be:

chmod 777 = User All Permission, Group All Permission, Other All Permission
chmod 764 = User All Permission, Group Read/Write, Other Read

In addition, there are three special permissions that apply: SUID, SGID and the StickyBit.

SUID = gives object special temporary root privileges
SGID = Allows files created in a directory to automatically belong to a group
StickyBit = allows users to modify a file, but only its creator may delete it

Example: chmod 7777 = SUID, SGID and StickyBit set, all permissions to user, all permissions to group, all permissions to Other.

Examples of Linux permissions configurations and commands can be found here: Linux Permissions .

Linux also supports access control through “su” and “sudo”. These are commands that allow the user to log in with fewer privileges than the root account, while still maintaining the ability to execute programs that require root privileges. The “root” account is equivalent to the “administrator” account in Microsoft operating systems. Logging in with fewer privileges is safer, as any malicious programs or scripts using the current login’s credentials will most likely have insufficient permission to function properly. When the user requires root privileges, she or he types sudo and their root password before executing a program. It is equivalent to the SHIFT – Rt. Click – “Run As” or “Run As Administrator” feature in XP/2003/Vista. The idea is the same – logging in with fewer privileges is safer. Linux’s sudo command is also similar to Vista’s UAC (User Account Control) – and sometimes just as annoying! ;-(

Security: In addition to sudo and POSIX permissions, Linux comes with a built-in firewall and intrusion detection system. The firewall system is called “IP Tables”, and is configurable from the command prompt or the GUI. In IP Tables, there are three “chains” – INPUT, OUTPUT and FORWARD, corresponding to the direction of network traffic. Rules may be layered, one on top of another, and linked to these chains to control ports and services and access to and from IP and MAC addresses. In addition, traffic may be filtered on flag and bit information.

Networking: Linux offers a large selection of networking services. For communication with UNIX and other Linux systems, NFS. For communications with Windows systems, Samba and CIFS (Common Internet File System). Linux may be configured as a web server (apache daemon), ftp server (vsftpd or ProFTPD daemons), proxy server (squid daemon), DNS server (BIND daemons), router (radvd daemons), authentication server (NIS daemons), VPN (vpnd) server, RDP server, mail server (sendmail and many others) or firewall/IDS system.

Linux employs TCP/IP as it primary protocol stack, while also supporting the IPX/SPX protocol stack and Windows NetBEUI/NetBios standards through SMB and CIFS. Linux routing daemons support static route tables and dynamic routing protocols such as RIP v1 and v2 and OSPF. When setting up VPNs, it can support PPTP with MPPE for encryption and L2TP with IPSec.

There are now open source products that offer Desktop management for Linux such as Xandros’ “xDMS”, which allows software inventories, the establishment of managed groups of networked PCs, the creation and enforcement of custom desktop configurations for specific departments, the imaging of PC configurations, the performance of scheduled OS installation, and updates, and monitoring capabilities. Novell’s “ZENworks” is another alternative. Together, these solutions give a Linux environment the effect of Microsoft’s Group Policy tools. A partial listing of Linux networking services can be found here: Linux Networking Services .

 

Multi-Media: Linux now offers good support for multimedia.

Check out my rotating 3D desktop HERE: 3D Linux Desktop Running BERYL.

For multimedia, you need to configure a Linux system a bit “a la cart”. For online content Linux offers Flash, RealVideo, and a complete Java VM. For movies and video, “mplayer” will play just about anything – avi, DivX, wmv, mpeg, flv, mov and 3GP files. The Linux equivalent of WinAmp or MediaPlayer is “xmms” – it can be configured to play MP3s, wmas, MIDI, wave and VQF content. In addition there are CD/DVD burners, video editors, graphics editors, DVR software, 3D design tools like “Blender”, music composition software and a decent assortment of OpenGL games. For virtualization, VMWare offers a free virtual machine server that supports DirectX technology.

In addition to running XP/Vista/2003/2008 in a virtual environment on Linux, if you install a program called “Wine”, you can run Windows programs ona native Linux system. Wine accomplishes this by creating the directories that Windows programs like and a registry. It does not run all Windows products, but I have successfully run Office 2003, Half-Life, Counter-Strike, and WinAmp under Wine. Several popular games also have Linux ports, such as Doom and Unreal Tournament. The major drawback in gaming with Linux is its lack of native DirectX support. Games have to utilize OpenGL in place of DirectX, as it is a proprietary technology. I do run DirectX on a virtual XP in Linux so my kids can use it as a video game machine while it performs its primary function as a file/web/ftp server. But running things through a virtual machine drains system resources for both the host and the virtual operating system.

There are thousands upon thousands of powerful, free applications under the GNU Public License for Linux systems. Some rely on an RPM (RedHat Package Manager) packaging format, whereas others us installation scripts and package managers such as the debian “Synaptics Package Manger”. RPMs have an extension of “.rpm” and Synaptics packages an extension of “.deb” (from Debian). These managers are equivalent to the Windows installation services manger WinSIM and Windows Installer files with an extension of “.msi”. They automate and simplify installation and removal of applications as well as resolve inter-dependency issues.

©2008 C. Germany

Shell Flavors

sh - Bourne Shell (first)
ksh - Korn Shell (popular Unix)
csh - C Shell (Job Control)
tcsh - Enhanced C shell
bash - Bourne Again Shell
zsh - newest shell, Bourne compatible


File Type Indicators in Display

* = program/executable script
/ = directories
@ = symbolic links
| = pipes
= = sockets
nothing = regular files

Relative path = you don't provide a leading / the shell will append the change to the current working directory.  If you were in home/alberto/ and you typed in cd images/anotherdir and typed pwd it

would now be home/alberto/images/anotherdir.  the current directory can be specified using a period . and

The parent directory can be specified with two periods .. .

vi - text editor.  Commands:

l - forward
h - back
j - down
k - up
w - one word forward
b - one word backward
i - insert text/begin editing
x - delete selected character
dw - delete until end of word
d$ - delete text till end of line
dd - delete current line
u - undo last command
U - undo any changes to the line
Ctrl + R - redo any undos

Esc - return to command mode, cancel current action, repeat till vim beeps.

:q! - quit without saving
:wq - save and quit
:wfilename - write buffer to filename

Note: You can access shell commands by preceding them with an exclamation point (!):  Example:

:!shell command
:r! = insert results if shell command into text file in vi. (cool!)

Ispell - checks spelling in a file.  Syntax:  Ispell filename.

 ; - separates commands on a command line, enables using seveal commands at once.  Example:

pwd; cd ..; pwd; ls -l

Note: The rest of the stuff below on this page is just scribble that I haven't had time to format and edit. So to continue studying for your Linux+, go to the section 2 link below and some day I'll get some time to finish this introduction page.

------------------------------------------------------------------------------------------------------------------------------------

Old Stuff:

noclobber - keeps you from accidentally erasing files when redirecting. Set it to:
noclobber=1  to activate it (true).

You can use cat and redirection as a minimal text editor:

Type: cat > message.txt   (redirects output from screen to file)
Type: This is a test.  Until I type Ctrl + D I can type anything i want, even new lines.
Press: Ctrl + D to stop redirection.
Type: cat message.txt

 >> - appends to an already existing file. example: cat >> message.txt   (appends to the file)

 STDIN(assigned # = 1) - standard input (usually keyboard)   Must include assigned #.

 Syntax:   command  outputfile 2> errorfile               Example:

ls -R / > filelist.txt 2> error.txt   (Redirects good output to filelist.txt and errors to error.txt)

STDERR (assigned # = 2) - standard error stream (usually keyboard)

emacs - text editors, e-mail, web browsing, everything - an entire OS envronment

Note: Command groups and redirection.  In order to redirect the output of multiple commands you must use a command group.  Example:

pwd; cd ..; pwd; ls -l > /tmp/listing    (only redirects the output of the last command)   but:

(pwd; cd ..; pwd; ls -l ) > /tmp/listing   (places output of each command in succession to /tmp/listing.)

Pipes - allow you to use the output stream of one program as the input stream of another without the need for temporary files.

wc - counts the number of words, lines and characters in a file.
who - gives information about users on a system
who | wc -l   =  will give the who output without the extraneous information by using pipes "|".
ls | less = will list files stopping for you to press a key before going on to each page.

Note: UNIX computers all have a special file in the /dev directory called /dev/null also commonly called the "bit bucket".  Any data sent to /dev/null is thrown instantly.  To throw away the lists of files and keep just the errors you'd type:  ls -R / > /dev/null 2> error.txt.

Input Redirection: redirect input so text from a file is treated as characters typed from keyboard. Example:

 

1. You create a file called "prepare.txt" using vi (vim) which looks like this:

10dd

:w/outgoing/memo.txt

:q!

2. You prepare a memo by redirecting its input from the text file you created:

vi /incoming/memo.txt < prepare.txt.

3. You get the warning "Warning: Input is Not From a Terminal".

4. The memo is created and processed and the command prompt returns.

Metacharacters (wild cards) - The character * . Used to match like phrases. ANYTHING.

*.txt = match all files ending in ".txt"

file* = match all files beginning with "file"

file*.txt = match all files beginning with "file" and ending with ".txt"

? = matches a letter only

file?.txt = match all files the begin with "file", are followed by a single character and end in ".txt".

 

[ ] = matches a range of characters.

file [12].txt = matches "file1.txt" and "file2.txt" and nothing else.

file [0-5].txt = matches files "0-5.txt".

 

! = negates a range.   Example: fl1[!1]

 

Command History:

!!= repeats your last command

! + command # repeats that command.  Example:  !138

 

& = places a command or job in the background  Example:

 

1. you enter:       ls -R / >filelist.txt 2>error.txt &

2. computer displays:    [1] 872  and returns to command prompt.

 

872 is the process ID.

Note: When refeering to a job # ALWAY precede it with a % symbol.

 

3. When complete you'll see:  [1] -   Done    ls -R / >filelist.txt 2>errors.txt

 

fg - brings a process running in the background to the foreground.  Example:

 

1. You are telnetting in the background and see:

[1]+ stopped (tty output)  telnet localhost

 

2. Keystrokes are required.  To bring the job to the foreground type:  fg %1

 

3. Type what you need to.

 

bg - runs a process in the background

1. FIRST put the forground process to sleep by pressing CTRL + Z.

2. Then type:    bg %1   (this will revive it in the background).

 

jobs - lists all jobs started from within the current shell.

 

kill - kills/terminates a job that is currently running.  Use with process ID/job #.

CTRL + C - kills a job running in the foreground.

kill %1 or kill 872 - kill jobs running in the background by using kill + the job # or process ID.

 

man - brings up a manula page about whatever you type after man.

SPACE = view next page

/ = type / + a word to find that word in the document.

q = returns to command prompt.

 

apropos = searches for keywords instead of commandes (must build database first).

 

whereis + command = locates directory path and man pages for file specified.

 

--help or -h = provides help when added to end of a command.  Example:  ls --help | less.

 

Note: on-line help is in /usr/doc.

Note: less and more are called "pagers".

 

lynx - text-based linux HTML browser.  Type to activate.

 

LDP = Linux Documentation project

 

zless - reads compressed documents (with extensions .qz, .z, or .Z)

zcat - reads compressed files.  Use with a pipe.  Example: zcat | less.

 

info - type at command prompt.  Type "h" to activate the on-line tutorial.

 

Info Commands:

SPACE - page down

BACKSPACE - page up

b - beginning page

? - help

n - next node

u - previous node/up

l - last node

m - menu

CTRL + G - cancel current operation (or menu)

f - cross reference (type name or ? for options)

d - show directory of all documents info knows about

 

Permissions:

UID - User ID

GID - Group ID

 

Display: ls -l

drwxrwxr-x  4 alberto alberto  1024  Aug 2 14:39 stuff

The first character is the file's type:

d = directory

- = normal file

l = links

c or b = devices

s = sockets

= = pipes

 

The first 3 after this character are the Read, Write, and Execute permissions of the user: rwx

The next 3 are the read, write and execute permissions of the group: rwx

The last 3 are the read, write and execute permissions of others: r-x (no write priveledges).

 

id = shows what user groups you belong to

 

su = substitutes your GID and UID with those of the user you become and grants those permissions

 

newgrp - allows changing group ID's you want to use as defualt for sessions.

 

pseudouser accounts = important for the system to perform tasks while still upholding the permissions mechanism.  (Including: bin, adm, lp, sync, halt, mail, etc.)

 

Note: Each user name and account has its own home directory insode the /home directory.

 

chmod = changes file permissions.

 

Setting by Numbers:

0 = NO permissions

1 = EXECUTE permissions

2 = WRITE permissions

4 = READ permissions

 

For READ and WRITE permissions simply add 4 (READ) + 2 (WRITE) = 6 (READ and WRITE)

For READ and EXECUTE permissions add 4 (READ) + 1 (EXECUTE) = 5 (READ and EXECUTE)

For READ, WRITE, and EXECUTE add 4 + 2 + 1 = 7 (READ, WRITE, and EXECUTE)

 

There are 3 groups: the user (you), the user group, and everyone else.

You must do this for each group.  Each number place represents a group. Example:

To assign read, write and execute permissions to all 3 groups youd chmod 777.

To assign read, write and execute permissions to user but only read to group and others chmod 644.

 

Permissions Using Symbols

u = user/owner

g = group

o = others

r = read

w = write

x = execute

 

The syntax is as follows:

chmod + identity - permissions to deny     and     identity + permissions to grant.

Examples:

chmod "files" ugo-rwx = deny owner, group and others read, write and execute priveledges.

chmod "file" o - rw = deny others read and write priveledges.

chmod "file" go + x = grant group and others execute permission.

chmod "file" a + w = grant all write permissions (a stands for all, same as ugo).

g + s = setuid and setgid

a + t = sticky bits

 

Note: chmod does not change the permissions MODE of a symbolic (soft) link.  Permissions of symbolic links are never used.  Instead chmod will change the permissions mode of the file the link points to.

 

setuid (value = 4000) - sets USER ID of running program to user ID of the owner.  This way the program can run with permissions that the user doesn't have. 

 

setgid (value = 2000) - sets GROUP ID of running program to group ID of owners.  This way the program can run with permissions that the user doesn't have.  It also has a SPECIAL use.  When set on a directory, it sets the group ownership of files added to the directory.  This way even though the default group for a particular user is different than that of the established group, it is assigned to the project directory so it will be accessible to the entire group.

 

sticky bit (value = 1000) - used to protect files in a directory.  When set it only allows the owner of the directory, the file or the superuser. This is how directories like /tmp that are shared by many users have a little more privacy than they would have using the standard chmod permission settings.

 

Example:

If a directory is 777, you can set the sticky bit by adding 1000, so chmod 1777.

To set setgid you would chmod 2777.  To set setuid you would chmod 4777.

 

umask - defines the default permissions settings set when a file is created and saved.  Works like chmod modes but the bits are inverted.  Type umask to view the current umask.  Common umask values:

 

                         user           group           other

000 =                rwx             rwx               rwx

002 =                rwx             rwx               r-x

007 =                rwx             rwx               ---

022 =                rwx             r-x                 r-x

037 =                rwx             r-x                 ---

077 =                rwx             ---                 ---

 

Note: Your default umask depends on whether or not your administrator added a User Private Group (UPG).

If your account has a UPG, the default umask is 002, otherwise it is 022.

 

User Private Groups (UPG's) - Group ownership.  You want to collaborate with different users on a project.   So files will be editable and protected for all, you need to use groups.  When users are added to a newly created group, files for group collaboration are put into a neutral directory.  This directory allows read, write and execution priveledges to members of the group.  The setgid bit is set on the directory to ensure that files created in the directory belong to the group. 

 

This creates a problem because the permission of files will be set according to the user's umask and so will depend on whether the user has a UPG. 

 

When UPG's are used, instead of users belonging to the generic group "users", Linux creates a UPG for the user when the account is added.   The user is the ONLY member of his or her group.  This exclusiveness allows the user to have a umask of 002 (files default to full permissions for user and group) without compromising the security of any personal files.  In a UPG, the group linked to the file is also the owner so things are safe.

 

If a UPG is not used, members will have to be systematic about how the umask they use when creating project files.  Most files will end up by default being editable by the owner only and require a chmod to allow permission to others.  The UPG provides a solution to this problem.  Cool!

 

passwd - changes password (will ask for current password then allow you to change to ne password).

The superuser can change ANY password with the root password.

 

chsh - changes the shell.  Use more /etc/shells to get a listing of the available shells the type:

chsh and when prompted enter the path to the shell such as "/bin/bash".

 

chfn - change finger name.  Changes personal information. (The info available with the FINGER command - usually disabled for security purposes.)

 

who - tells who is logged into the system

 

w - tells who is logged in to the system AND what they are doing.

 

date - by default it will print the current date and time when you enter it.  To get time/date type:

 

date + %

 

H - 24 hour format with leading 0's (00...23)

I - 12 hour format with leading 0's (01...12

k - 24 hour  (0...23)

l - 12 hour (1...12)

M - minutes

p - am or pm

r - 12 hour with am/pm

s - # seconds since 1/1/70

S - seconds (oo...61)

T - 24 hour (hh:mm:ss)

X - local time's representaion

Z - time zone

a - abbreviated weekday

A - full weekday

b - abbreviated month

B - full month

d - day of month (01...31)

D - date as mm/dd/yy

j - number of day in the year

m - month

U - week number of year

w - day of week in numbers (0=Sunday)

W - week # of year (Monday is first day)

x - date representation mm/dd/yy

y - last 2 digits of year

Y - year (using 4 digits i.e. 1999)

 

Example: To print date in long format you'd type: date + "%A %B %d %Y" and linux would display:

Sunday September 20 1998

 

Note: Including "" is necessary so shel doesn't think it's getting 4 different commands.

 

setting date - just type date and  MMDDhhmmYYYY.  Example:

date 063001011999   (sets date to June 30, 1:00a.m., 1 minute, 1999)

 

cal - prints calender.  By itself it lists for a single month.  With a year as an argument it lists every month. Example: cal (calender for this month)     cal 1999  (calender of every month in 1999).

 

find - finds files.  Syntax:  find  paths  expression.  You can search multiple paths for a file because the expression list doesn't start until find locates an argument that begins with a dash - .   Can find files by name, modification time, etc.

 

-name = the most basic of options. Tells find the name of the file you're searching for. Good with wild cards.

 

-print = tells find to print any matches to terminal.  Optional in Linux but required on some Unix machines.

 

Example:  find /home/alberto /tmp -name "*.txt" -print

 

Note: Quotation marks used to avoid having the system glob (interpret) and expand star itself.

 

locate - locates files faster than find. Must use with a current database.  Type locate + filename.

 

updatedb - updates database for use with locate.  You must run it from /usr/bin/. Type:

/usr/bin/updatedb .Program takes a whil but when complete you have a current db for use with locate.

 

grep - searches for patterns inside of a file.  Example:  You want to find text files with the word "command" in them.  You type   grep command *.txt   and hit ENTER.   Grep print out the entire line of text where it found the key word/s.  A special option, -c , prints the number of time the word was found in the file.  Example: grep command -c *.txt

 

Note: The grep comand can also be used in a pipe to filter output you get from other programs. Example:  you want to see a list of users on system coming from the IP address 192.168.  You type the following:

w | grep 192.168   .  All the users from 192.168 are displayed.

 

wc - counts words. lines and charaters in files.  Syntax:  wc [options] files .

-c = print only the number of bytes.

- w = print only the number of words

- l = print only number of lines

*If you don't supply an option it prints all.

*You can supply more than one file (separated by spaces) and get results for all.

Example: wc /etc/passwd  /etc/group 

 

sort - orders lines in a file accorrding to numeric value.  Uses notation of fields, where line of text represents various bits (fields) of data and each line in the file represents a record.  Fields are separated by special characters such as commas, semicolons, colons, periods, etc.  Options are:

 

-t = specify field separator

-n = specify numeric sorting

-k = specify fields where sort will take place (default is first character on line)

-f = ignore case ("B" and "b" are treated as equals)

-r = reverse result

 

Example: You want to sort the /etc/passwd file according to user name.  You type:

sort /etc/passwd .  To sort the file numerically according to UID, knowing the fields are separated by colons and  the user ID is the 3rd field, you would type:  sort -t : -k 3 -n /etc/passwd .

 

fmt - applies wordwrap to any file.  Example:  You type in cat intro.txt and notice the words are out of place.  You then type:  fmt -w 68 intro.txt  . The text displays wrapped next time you cat it.

 

split - can split files up that are to large to go on one disk to go on several diskettes. 

Syntax: split [option] size file outfilename .  Options are:

 

-l = splits a text file by line count.

-b = splits a file by byte count. (add b fof bytes, k for kilobytes, m for megabytes)

 

"file" is the name of the file you want to split.

"outfilename" is the base name the command will use to name all the chunks. 

*Different filnames are created  by appending an extension to the file.

 

Example:  You want to split a large file into 1395K chunks so each chunk fits on a floppy.  You type:

split -b 1395k book.zip book.zip

 

Note:  There is no "join" command, so to join the chunks back together use cat and type:

cat book.zip.?? > book.zip   (using wild cards and redirection).

 

telnet - used to access other computer remotely.  Use stty to fix terminal problems and type "exit" or hit "CTRL + D" to exit from a telnet session.

 

setfont - changes font used by console to different size.  Fonts are located in /usr/lib/kbd/consolefonts .

To change the font just type:  setfont fontname .

 

pr - print comand.  Prints file.  Example:  pr intro.txt  (prints intro.txt to non-postscipt printer)

 

enscript - print command.  For postscript printers.  Example: enscript intro.txt

 

setting margins you'd type: fmt -w 65 intro.txt | enscript -- margins=100:100:100:100: -h -B

(-B suppresses printing header) (-h suppresses printing banner page)

 

groff - formata, produces fancier outpur, bold, italics, etc.  (If you look at the source of a man page you'll see the formatting codes used with groff.  To do this, use "zless" on any inside of /usr/man/man1.).  Linux and some versions of Unix use troff instead of groff.  

 

lpr - takes whatever you give it (man pages, text, HTML) and spools it to the printer.  Example:

 

nroff -Tps -macropackage filename | lpr   .

 

"macropackage" = name of macros (man, ms, me, mm, etc.)

 

User Groups and Passwords:

 

adduser - adds a user and manages the groups database and implements the UPG scheme.  Syntax is:  adduser username.  It will assign a UID and GID. 

 

useradd - adds a user without managing groups or UPG scheme.  Use the "-m" option to create the home directory.   Example:  useradd -m username. 

 

usermod - modifies and makes changes to existing user accounts.

 

Example: usermod  -d  newdirpath  -m  login

The -d option modifies the location of the home directory specified by /etc/passwd file to point to the directory specified by the -d option.  It will create the directory if it does not exist.  The "-m" option moves the contents from the old home directory to the new one. 

 

Example: usermod  -l  newlogin  currentlogin - Changes a user' s login name.  All other info remains the same.  To change secondary group memberships:

group - used to modify group memberships.

usermod -d newdirpath -m login

usermod -d /home/newflower -m flower

groups flower

flower: flrower users

usermod -G wheel, database flower

groups flower

flower : flower wheel database

 

usermod -G username username - removes all group affiliations from a user.

 

userdel - deletes a user from the system.  Syntax:  userdel username.

 

groupadd - adds a group.  Must use a GID not already used. Syntax: groupadd -g GID groupname .  Example:  groupadd -g 600 weirdgroup

 

gpasswd - manages the group file.  The "-a" adds users and the "-d" deletes users.  Example:

gpasswd -a username groupname     or    gpasswd -d username groupname .

 

shadow passwords - protect system passwords by making them only readable by the root level user.  To check type "ls /etc/shadow" and make sure te system finds it.

 

passwd - changes a user's password.  Syntax:  passwd username password

 

tar - compresses and decompresses files.  Syntax: tar options destination sources.  Options:

 

c = compress/create an archive

x = extract files from tar

v = verbose (list each step)

f = put the archive in a file or device

 

tar  cvf  /tmp/bkup.tar  /home/alberto  /var/spool/mail/alberto = back up home directory & mailbox into same archive file.

tar   xvf   /tmp/bkup.tar   / - Decompresses bkup.tar.  The last part "/" specifies path where you want to decompress to.

 

*Most important about TAR files is that you can extract directly into a device such as a tape drive that doesn't have a file

system and so can't be mounted or accessed in the same way that you access you disks.  It will store all the data into 1 file. 

So if you tar into a tape or floppy, the entire floppy or tape is treated as 1 file.   You can store multiple tars in a tape.  You
can't mount a tarred floppy because it has no file system.  Normal floppies and CD-ROMS can be easily mounted and unmounted

in the KDE desktop.  To tar to a device specify its path  in the destination.  Example:

To create a tar on a floppy you type:

 

fd = floppy device

tar cvf /dev/fd0 / etc /home/alberto/nsmail

 

st  = SCSI tape device

rft = IDE floppy tape devices

tar cvf /dev/st0 / etc /home/alberto/nsmail

 

mt - tapes commands.  Allow you to rewind, fast forward, etc. 

rewind = mt /dev/nts0 rewind

forward over next 2 archives = mt /dev/ nst0 fsf 2

forward over next 1 archive = mt /dev/ nst0 fsf 1

 

device extraction = tar xvf device path .

 

spanning multiple tapes and disks - Use the "M" option in tar. Each disk or tape is treated as a separate archive and can

be worked with accordingly, thgouh the files at the end of each tape/floppy might be on proceeding ones. Example:

 

tar  cMvf  /dev/fd0  /home/alberto/nsmail

 

To extract a multi-volume archive type:

 tar  xMvf  /dev/fd0  

 

dump - Note: To install it type:  rpm -i dump*.rpm  . Handles backups that span multiple tapes and incremental backups. 

You can automate backup tasks onto on device.  "dump" only backs up files that have changed by keeping track of what

was dumped before.  "dump" can only back up entire systems, not single files or directories.  For single files and directories

use tar and cpio.  Back up at well defined times:

 

1- after system software is installed but before anything is configured

2 - after system software is installed and configured

3 - any time additional software is installed and configured

 

By this philosophy, do your 1st backup with "dump" after your installation to /dev/null which will simply discard the data.

"dump" will keep track of the date it last dumped.  The next backup will only back up things that have changed since the date

of the first backup.  This backup level is "0".  The lowest level, it includes everything in the newly installed system. 

Example of "dump" levels are:

 

0 = backs up everything

1 = backs up everything modified after the level "0" dump

2 = backs up everything modified after the level "1" dump

 

Syntax:  /usr/etc/dump [options [argument ...] filesystem] 

 

dump  -0u  -f   /dev/nst0  -s  112778  /dev/hda1 - "nst0" = name of tape device.  "hda1" = Name of device with root partition.

dump  -9uf  /tmp/backup  /dev/hda1 - redirects backup to file using "-f" option.

dump  -9uf -  /dev/hda1  |  gzip  >  /dev/st0 - redirects output of dump to STDOUT using "-" and gzip.

 

Note:  Backups created with dump are not readable on other machines or in earlier versions.

 

restore - extracts files backed up with dump to the current directory.   It will create directories and clobber files existing with the same

name.  Syntax:  restore  -f  /dev/nst0  -i . The "-f" option specifies the location of the backup file and the "-i" option activates an

interactive session.  When restore loads you can use cd and ls to move around in the tape catalog.

 

add - adds a file to a list of files you wish to extract.  Syntax:  add filename.   

del - deletes a file from the restore list (not off the tape, just the list)

extract - extracts files specified by restore.

? = help

quit = exit

 

Note: Reply "no" when asked if you want to set the owner/mode for '.' .

 

You can restore a particular file by:

 

restore  -x  home.alberto/file.rtf  -f  /dev/nst0 = restores just the file "file.rtf".

Make a tape catalog - use the "-t" option:

restore  -t  -f  /dev/nts0  >  tapecat.txt = creates a catalog of every file on the back up tape.

 

rpm - installs, uninstalls and maintains a database of softwrare and its interdependencies.  It makes sure you have

everything installed needed to run a new program.  it can be run through FTP to download and instal a package at

the same time.   Syntax:  rpm  -i  thepackage  -1 .0 -2.i386.rpm

 

The "-i" option for installing and replacing packages:

1. rpm  -i  thepackage  -1 .0 -2.i386.rpm - installs a new package.

2. "--replacefiles"  =  rpm  -i  --replacefiles mypackage - 1. 0 -2.i386.rpm  = replaces installed files

3. "--replacepkgs"  =  rpm  -i  --replacepkgs mypackage - 1. 0 -2.i386.rpm  = replaces installed packages

 

The "-U" option for upgrading:

1. rpm  -U thepackage - 1.0 -4.i386.rpm = upgrades from a previous version.

2."--oldpackage" = rpm -U --oldpackage  theoldpackage  - 1 . 0 - 1 . i386.rpm = downgrades to a previous package.

3. "-e" =  rpm  -e  thepackage  = erase or uninstall package.

 

"-q" option = queries database of installed software.

1. rpm  -qip  thepackage = quereies database for information about package.

2. rpm -q -f thepackage - finds what package a file came from

3. rpm -q -l thepackage = finds all the files owned by a package.

4. rpm -q -d thepackage = finds all sources of documentation about a package.

5. rpm  -Vp  thepackageinstalled  thepackageondisk = compares/verifies installed packages

 

gzip - ".gz" Unix compressed files.    To extract them specify the "z" option to tar.  Example:

tar  -xzvf  file.tar.gz

 

1. gunzip filename.gz  = uncompresses gzipped file.

2. gunzip filename.tar.gz = renders "filename.tar",  then you

    tar  -xf  filename.tar.  (Inefficient, uses more disk space).

 

gzcat - reads gzip files.

 gzcat file.tar.gz | tar -xf -  =  Gzcat is similiar to cat.  This uses redirection.  "gzcat" reads the compressed contents and

pipes them out to 'tar".  The "tar" program looks for data in the STDIN stream because the "-" was provided to the "f"

option as an argument.  (More efficient, uses less disk space.)

   

zip - winsdows compressed archives.  Syntax: unzip/zip filename.zip

 

Note: Caldera has a "LISA" configuration utility for automating many tasks.

 

Monitoring the System:

Note: the single most important thing is that you have enough RAM to keep things going and avoid too much swapping.

 

free - displays how much memory is available in RAM and the swap file (virtual).

 

procinfo - displays more detailed memory information, last boot, load average, # processes, time spent in user code,

system code, and idle, "nice time" user code with lower priority, time system has been up and running, activity of devices
and IRQ/DMA settings.
 

 

top - lists current top processes, refreshes once per second, real time what your machine is doing. Top commands:

SPACE - updates display

CTRL + L - redraws screen
 ? - help

 i - toggles display of idle processes

c - togles display of command name/line

l - toggles display of load average

m - toggles display of memory information

t - toggles display of summary information

k - kills a task (with any signal)

r - "renices" a task (changes priority)

P - sorts by CPU usage

M - sorts by resident memory usage

T - sorts by time/cumulative time

n - sets the # of processes to show

s - sets refresh rate

q - quits

 

ps - process status.  Good for finding the PID of a process so you can nice it or kill it.  To display a list of all processes running

on the system you would type:  ps aux  .

 

kill - terminates a process, use only as a last resort to terminate a malfunctioning program.  Syntax:  kill PID   Example:

If the process ID you wanted to kill was 188 you'd type "kill 188".

 

*If kill is unable to stop the process use:  kill - 9 PID (signal 9 is the strongest kill) or its equivalent kill -KILL PID .

*Some processes that run as daemon such as "httpd" can be restarted by sending them the hangup signal - "-HUP".

Example:  kill -HUP 188  will cause the process to restart and  reread its configuration files.

 

nice - starts processes/programs with lower or higher priority.  Syntax: nice programname . To start a low priority program just

type: "nice programname".   Priorities range from the HIGHEST - 20,  to the LOWEST 19 .  Only root can assign a high or

negative priority to a process.  By default "nice" will add 10 to any process.  You can specify the nice range by using "-n", the

priority number, and then the PID.  Example:  nice -20 reallybigjob - Puts highest priority on the program "reallybigjob".

*"nice" only works on jobs that have not started.  To make an existing process nice you use "renice".

 

renice - Makes an existing process "nice".  Example: renice -10 188 = Gives high priority to process 188 already running.

 

du - gives listing of how much space a directory takes up in 1K increments.  Use "-s" to summarize output.  To specify specific

directories or files to list provide their names as arguments: du -s *

 

df - finds amount of disk space available on devices in system.    "-i" checks the inode table to see if it is full.  Example: df -i .

 

last - monitors user logins and logouts.  Example:

last - gives info on all users.

last username - gives info on just that user.

 

lastb - enables and displays bad logins.  To enable use the "touch" command to create the file: touch /var/log/btmp .

 

disabling an account - Easiest way is to put an * before the encrypted password in the /etc/passwd file.  (Passwords are

the 2nd field in this file.)   Fields are separated by colons.  Example: me:*Ms.7kvaAYyHbU:500:100:Me:/home/me:/bin/sh.

If using shadow passwords the easiest way is to use "usermod" to expire it "-e" with a date in the past:

usermod  -e  09/01/98  username  .

 

mount - grafts a file on a device or network to a local directory on your system.  If the directory has files, those file are hidden from

view until the mount is removed.  The file /etc/fstab contains a list of all mounts on your computer.  If any line in the fstab file

contains the "user" option then a non-root user can use the "mount" command to mount that device.  Just specify the name of the device or mount/mount point.  Example:  To mount a floppy just type:  mount  /mnt/floppy       or       mount  /dev/fd0 .  To mount a NFS volume just

type:  mount host:/path dir    and    mount -ro digital:/share /net/digital .

 

unmount - Unmounts media using same syntax.  Don't forget you must UNMOUNT after mounting!

 

ftp - connects to ftp site.  Commands: "ls", "cd", and "exit".  "ascii" and "bin" toggle text and binary. 

get - downloads a file

reget - resumes a broken download

mget - downloads multiple files

hash - enable a progress indicator when uploading/downloading.

put - uploads a file

 

FTP server - provided by default where your /etc/passwd file contains an entry for the FTp user.  Users who log in as FTP are placed

in the /home/ftp directory.  This directory is treated differently by the FTP daemon.  Anonymous users see /home/ftp as a root file

system.  They can not change directories outside it and only have access to directories in it.  The FTP daemon accomplishes this

by changing the server's root for the FTP process to the /home/ftp directory which contains minimum/etc and /bin directories with

just enough info and software to allow anonymous users to access the system. You should not modify the contents of /home/ftp/etc

and /home/ftp/bin unless you really know what you are doing.    To publish files:  As root create a directory inside /home/ftp/pub and
make sure that permissions for the directory are 755.  Anonoymous users will be able to download from but not upload to the directory.

 

inetd - Network services are handles by a program called "inetd".  The program listens for network connections and when it gets one makes sure the right server is connected with the client.  You may not want everyone to be able to connect to your system via FTp for security reasons.

For this use "tcpd".

 

tcpd - handles requests for programs like FTP and telnet.  When a connection is received it tries to determine if it should allow a connection based on where the user is coming from.  "tcpd" consults the files /etc/hosts.allow and /etc/hosts.deny to see if the client (system trying to connect) falls into any of these categories.  By default any client not explicitly allowed is denied access.  To enable access for other hosts you'll need to edit the /etc/hosts.allow file.  Do a "man 5 hosts_access" to obtain information on how to configure this file.

Example:  To enable access to hosts from all domains for all services you would enter:   "ALL:  ALL" in the /etc/hosts.allow file.  For more

info consult the man pages for: "tcpd", "inetd", and "host_access".

 

ftpd - Same for FTP.  You can log everything.  Do "man ftpd" and "rpm -qd wu - ftpd" for list of documentation.

 

Note: To create a more secure FTP directory mkdir in /home/ftp/pub called "incoming" and from /home/ftp/pub chmod the new

"incoming" directory to 1733.  This will allow users to put and upload/write files but not to list/read them.  They can only

download the files if they know the name of the file. 

 

FTP - File Transfer Protocol

NFS - Network File System.  Shares files between UNIX machines.

HTTP - Hypertext Transfer  Protocol

*Before exporting an NFS volume enable NFS services on your system.

 

Apache server - powers 50% of the web.  Apache's configuration files can be found in /etc/httpd/apache/conf .  Directives appear 1 per line.  The 1st word on the line is the directive, the rest are parameters.   The configuration is done in three text files: 

 

1. httpd.conf - primary web server configuration file.  Set default behavior of server, name, port, location of configuration files, logs,

and error files.  The most important thing you need to change is "ServerName".  This should reflect a valid DNS name for your system.  If you don't knwo the fully qualified DNS name, leave it as "localhost".

 

2. srm.conf- keeps track of where information published by the web server resides.  It also provides a mapping between icons and files that

the web server uses when generating automatic file indexes.  3 important directives to know here are:

DocumentRoot - specifies where your HTML documents are found.  By default this points to /home/httpd/html  which contains Apache

Server documentation.

UserDir - specifies name of directory users can create in their accounts.  Files in this directory are accessible using a browser and a URL

such as http://servername/~username/ . 

DirectoryIndex - specifies name of files that will be loaded when a user requests a directory instead of an HTML file.  If this is not defined

the server will generate an automatic server index listing all the files in the directory.

 

3. access.conf

 

MIME - Stands for "Multipurpose Internet Mail Extensions".  MIME types are located in the "mime.types" file.  When the server sends a file to a borwser, MIME types tell the browser the type of data being sent. 

 

Password Protection:

1. Create a directory.  Name it whatever you wish.

2. Inside the new directory create a file called ".htaccess" (note the neame of the file begins with a period).

3. Inside the file type the following text:

 

AuthUserFile /hom/yourusername/.htpasswd

AuthName Alberto's Secured Area

AuthType Basic

require valid-user

 

AuthUserFile - specifies the location of the password file ".htpasswd" that will be used to validate users. (outside the public_html directory or document or DocumentRoot tree.) 

AuthName - identifies set of documents.  Displayed by browser in password request dialog.

AuthType - defines type of authentication used.

require - specifies that only authenticated users should be let in (valid-user option)

 

Creating the ".htpasswd" file:

htpasswd - manages web server passwords.  Syntax:  htpasswd -c filename username . (The "-c" option creates the file.)

Example:  /home/httpd/bin/htpasswd  -c  /home/alberto/.htpasswd  alberto  (htpasswd created ".htpasswd" in the specified dir.)

It will query for the password you supply and that's it.  Anyone who tries to access the directory will be asked to authenticate.

If successful they can acccess the directory.

 

SAMBA - acronym for SMB (Server Message Block) protocol.  Allows windows PCs to access disks and printers from Linux and

Linux to access disks and printers from Windows.  Download the latest version from: http://samba.gorski.net/samba/samba.html .

 

smbclient - allows Linux to access a PC network drive.  See man pages for more info.

 

"-L" - option added to smbclient that displays a list of services provided by the PC host.

"-U" - by default Linux attaches your Unix login name.  If your PC login name is different use "-U" to specify another name.

Example:   smbclient -L smbhostname -U pcloginname  .

*Sometimes PCs will not allow access unless you specify a login name in all CAPS.

 

shared - accesses a shared resource.  Example:  smbclient \\\\pri\\shared -U ARICART . Once in you can "ls" and use "get" to

copy files and "put" to write files.

 

Steps to recompiling the Linux kernel:

1. Select drivers and feature support you want

2. Compile the kernel and any necessary modules.

3. Copy the kernel to its proper place.

4. Install the new modules.

5. Configure and reinstall LILO to see the new kernel.

6. Configure the new modules and reboot.

 

You need:

1. the gcc compiler.

2. CD.linux-kernel-include-2.0.35-1.i386.rpm

3. linux-source-common-2.0.35-1.i386.rpm

4. linux-source-i386-2.0.35-1.i386.rpm

5. linux-source-doc-2.0.35-1.i386.rpm

 

Options:

1. Build support into kernel - fast launcing of modules, but more burden on system resources and slower boot.

2. Build support as external module - reduces size of kernel, efficient but requires much time to launch modules when needed.

 

There are 3 kernel recompiling tools:    1. config     2. menuconfig     3. xconfig  .

 

After setting up your changes and the new modules and service you wish to add, recompile the kernel with "make" by typing:

1. make dep

2. make clean

3. make zImage

4. make modules

*Note: This takes a while to process.

 

Installing new kernel - the newly built kernel is in  /usr/src/linux/srch/i386/boot/zImage .  Before installing it make sure you don't

overwrite the existing kernels in  /vmlinuz and in  /boot/vmlinuz-2.0.35-modular . Or whatever veriosn you may have.  If overwritten

and the new files do not work properly the new system will be unbootable. 

 

1. Copy the new kernel with a new name to the /boot directory.

Example:  cp /usr/src/linux/arch/i386/boot/zImage  /boot/vmlinuz-2.0.35-apm (renamed -apm for advance power management).

 

2. Install the new modules: Tricky because by default they wish to overwrite existing modules.  Modules are installed in the

/lib/modules  directory in a directory called after the kernel version.  (kernel version can be displayed with the "uname -r" command.)

Example:  /lib/modules/2.0.35  .  Save the current modules by moving them to a directory name perhaps "mv /lib/modules/2.0.35

/lib/modules/2.0.35-old"  Install the  new modules with "make modules_install" .  Set things back to the way they were.  Move

the new module contents in /lib/modules/2.0.35  to a new directory like something called "/lib/modules/2.0.35-apm.  Now move the

old module contents stored in /lib/modules.2.0.35-old back into /lib/modules/2.0.35 . 

 

3. Configure LILO to recognize the new kernel.  Open the LILO configuration file  /etc/lilo.conf .  The "default" entry is the on that

boots after the timeout period.   You can install new kernale as default but save the entry of the old kernel in case you need it to boot.

Insert the new entry above the old entry, using the old for a guide.  Specify values for image(kernel file), label(name displayed at boot),

and root(same as old).  Add the "read-only" line at end to specify file system checking at boot.  Example of default LILO file:

 

#

# general section

#

boot = /dev/sdbl

install = /boot/boot.b

# default entry

 

image = /vmlinuz

initrd ="/boot/initrd.gz"

label = OpenLinux

root = /dev/sdbl

read-only

append = "load_ramdisk=l ramdisk_size=288B"

 

#

# additional entries

#

 

Modified LILO configuration file with new kernel:

 

#

# general section

#

boot = /dev/sdbl

install = /boot/boot.b

# default entry

 

image = /bootlvmlinuz-2.8.35-apm

label = newkernel

root = /dev/sdbl

read-only

 

image = /vmlinuz
           initrd ="/boot/initrd.gz"

           label = OpenLinux

          root = /dev/sdbl

          read-only

          append = "load_ramdisk=l ramdisk_size=288B"

#

# additional entries

#

 

4. After editing the /etc/lilo.conf file test to see that it works with:  lilo -v -t.

5. If everything test o.k. create the boot sector by tyoing:  lilo -v.

6. reboot and configure the new modules.

*If you can;t boot hit TAB to boot from the old kernel.

 

By default Linux look for new modules in a directory with the same name as the kernel.  It expects to find a file named after

the time and date when the kernel was built followed by a ".default".  Example: #1 Tue Jan 6 16:44:51 MET 1998.default  .

The name the system expects is stored in the kernel itself.  To find it type:  uname -v .

 

Using the text displayed after typing "uname -v" you will create a new module list so that the system will load your modules

when it boots.  We will use a technique called "command substitution" (See man page for BASH).  Type:

 

# find /lib/modules/2.0.35-apm -name "*.o" -print > "/etc/modules/2.0.35/ $(uname -v).default"

 

This will find all the modules in the new modules directory, make a list of them and sends it to the correct file in the

/etc/modules/2.0.35 directory.  Without this command the modules will not load automatically at reboot. 

7. Now reboot again.  You're done.

Sound - use the utility  sndconfig on older Linux systems. On Fedora it's totally different. 

Note:  If you need to build boot floppies on diskette because the system can not boot from CD-ROM:

1. Put Linux CD-ROM in and a blank floppy.
2. Type: d:\col\launch\floppy\rawwrite3 .  (or possibly "rawrite3").
3. Enter  "d:\col\launch\floppy\install.44" when asked for the path name.
4. Type: d:\col\launch\floppy\rawwrite3 .
5. Enter  "d:\col\launch\floppy\modules.144" when asked for the path name.

©2005 C. Germany