Home
Collections
Build Your Own
Catalog
Books
Quick Reference
View Order Pad

About Us
Contact Us
FAQ
Linux News
Link To Us


 
 
Acceptance Mark





 

Linux Quick Reference

This is a collection of useful information when working with Linux. If you are new to Linux, some of this may be invaluable. If you are experienced, this reference may also be helpful in getting the syntax correct, or performing specific tasks.

Overview

This is a work in progress, and it is highly biased towards the specific needs of the author. If you have any input or feedback, or wish more details on any particular subject, please feel free to contact us.

For details on the history of Linux, UNIX, and the BSDs, there are numerous resources (Wikipedia - History of Linux is a good start). This is all about using these operating systems. The fact that these operating systems were written by developers, for developers, and have a history dating back to when bandwidth and storage space was valuable, means that not everything is intuitive or fits in well with the preconceived notions of different aged users or different cultures. More importantly, this means that not everything is necessarily obvious to any particular person. In fact, certain things only make sense when you understand the history and context of the decisions made during the design of a particular portion of the entire system. The reality is that not everyone has time to learn everything they need to know when a problem presents itself. The only choice then is to do what needs to be done.

This is not intended to be a comprehensive reference, nor a replacement for man or info pages. This is all about using Linux, and a place to find things that you might have used once, but that was years ago, and you need to do it NOW!

Here are a few sites that have some useful information and a good place to search for details:

Here are useful/interesting tools and applications:


The Beginning - Boot sequence summary      Boot loaders
fdisk notes      fsck notes
Linux directories      Integrate scripts with X
X server Notes      split, tar, gz (file size limits)
date - How to set the date / time      Accessing a CD/DVD ISO image
Obtaining MD5 Sum from CD      Controlling Users
Controlling Processes      smb:// or smbclient unable to connect by name
Manipulating images      Debian exim configuration
APT on CD      Debian package management
Debian Packages - Create Local Repository      Debian Configuration Notes
MySQL Statements Reference            

The Beginning - Boot sequence summary

BIOS

Load boot sector from one of: Floppy, CDROM, Hard drive
The boot order can be changed from within the BIOS. BIOS setup can be entered by pressing a key during bootup. The exact key depends varies, but is often one of Del, F1, F2, or F10.

Master Boot Record (MBR)

BIOS loads and executes the first 512 bytes off the disk (/dev/hda). This is very limited code, but typically enough to check for bootable partition and load the next stage (LILO/GRUB)

LILO

  • does not understand filesystems
  • code and kernel image to be loaded is stored as raw disk offsets
  • uses the BIOS routines to load
Loading sequence
  • load menu code, typically /boot/boot.b
  • prompt for (or timeout to default) partition or kernel
  • for "image=" (ie Linux) option load kernel image
  • for "other=" (ie DOS) option load first 512 bytes of the partition

GRUB

  • Understands file systems
  • config lives in /boot/grub/menu.lst or /boot/boot/menu.lst

Startup splash notes

  • The opening "splash" display is typically unique and a special aspect of a distribution.
  • bootsplash - requires kernel modification for framebuffer (video) interaction - be sure to review all options available
  • Splashy (user space, supercedes bootsplash)
  • Usplash (user space)
  • Red Hat Graphical Boot

Kernel

  • initialize devices
  • (optionally loads initrd, see below)
  • mounts root filesystem
    • specified by lilo or loadin with root= parameter
    • kernel prints: VFS: Mounted root (ext2 filesystem) readonly.
  • runs /sbin/init which is process number 1 (PID=1)
    • init prints: INIT: version 2.76 booting
    • can be changed with boot= parameter to lilo, eg boot=/bin/sh can be useful to rescue a system which is having trouble booting.

initrd

Allows setup to be performed before root File System is mounted
This ram disk is system dependent and typically must be generated when changes to the kernel or hardware affects the existing initrd. This is a tool that provides an environment for the kernel and system devices to prepare for loading other file system modules, and other pieces the kernel will need to operate the live system, prior to mounting the root file system.

  • lilo or loadlin or grub loads ram disk image
    • load modules
    • initialize devices
  • "real" root is mounted
  • kernel runs /sbin/init

/sbin/init

  • reads /etc/inittab which specifies the scripts below
    • Run boot scripts (system dependent /etc/init.d, /etc/rcS.d, /etc/rc.boot, /etc/rc3.d, etc.)
    • switches to default runlevel (e.g. 3)

Run Levels

  • 0 halt
  • 1 single user
  • 2-4 user defined (3 is typically multi-user, text console)
  • 5 X11 only (0 or 1 text console) (GUI environment)
  • 6 Reboot
  • Default is defined in /etc/inittab, eg:
    • id:3:initdefault:
  • The current runlevel can be changed by running /sbin/telinit # where # is the new runlevel, eg typing telinit 6 will reboot.

Boot loaders

GRUB Problem: You've just imaged a drive, and it won't boot.

Boot a live linux disk or 1st disk of installation, get to a rescue (or root) prompt - use these commands grub - gets you to grub> prompt

grub> find /boot/grub/stage1
indicates drive/partition grub stage1 is on, e.g. (hd0,1), or (hd0,0) Select root for grub operations:

grub>root (hd0,1)
Then setup this partition for grub booting:

grub> setup (hd0,1)
A list of "successful" operations should be shown.

Reboot the system.

When cloning a SUSE 9.3 workstation onto a different size drive, this will fail at GRUB - boot Knoppix (or rescue disc), mount /dev/sda1 to /boot, mount /dev/sda3 /mnt/sda3 then run grub --batch --device-map=/boot/grub/device.map < /mnt/sda3/etc/grub.conf

Then for good measure, run grub and to the above steps (root (hd0,1), setup(hd0,1), then reboot

Original SUSE notes:

Use:
grub --batch --device-map=/boot/grub/device.map < /etc/grub.conf
or edit /usr/sbin/grub-install script, and change (line 30):
pkgdatadir=${datadir}
to
pkgdatadir=${datadir}/${PACKAGE}/${host_cpu}-${host_vendor}

fdisk notes

fdisk is a partition modifier - it lets you create, modify, and delete partitions on a hard drive. IMPORTANT: You really want to understand what you are doing before you play around on an existing hard disk. Learn on a new hard drive to get some experience!

fdisk /dev/hda opens the partition of the first hard disk. Typically IDE hard drives / CD/DVD drives are hda, hdb, hdc, hdd. /dev/hda1 is the first partition on /dev/had, /dev/hda2 is second partition, etc. Typically sata & usb drives are /dev/sda, /dev/sdb, etc.
p - prints the current partition table
n - creates new partition
t - sets type (L lists types)
d - d deletes a partition
w - writes partition table to disk

fsck notes

fsck is the file system check tool. Learning about system maintenance is important, and not covered here. Most systems have a counter, and will force a check after every so many boot-ups or days. Generally everything is fine, until a forced check at boot up finds some problem, and halts the boot up process.

When this happens, here is a quick run-down on how to fix it, IF there isn't a serious problem with your drive, hardware, or system.

  • Review the boot messages and screen to determine which drive (partition) was being checked. In this example it is hda4.
  • If prompted, use your root password to log on into a maintenance mode. If not, restart as a single-user, or in rescue mode.
  • At the root prompt, type fsck /dev/hda4 (where the device is the device that failed the fsck)
  • Answer any questions, see what the problem is. If its serious, and this doesn't help you resolve it, refer to man fsck, fix the hardware/system problem, or start looking for your backups.

Linux directories

Use "man hier" for specifics about your particular system/distro. Even this might not cover all the root folders, such as dos, initrd, sys, etc., etc.

This is the reference: Filesystem Hierarchy Standard (FSSTND)

bin

bin contains the system binary files that are essential for the general operation of your computer. These executable files are critical to actually use your system. Some of these include: cp, ls, bash, mount, etc.

dev

All Linux devices are represented as a directory. This makes it easier for other programs to interact with them. For example mount - You can use the system binary mount in the /bin folder to interact with a removable hard drive for example (e.g. mount /dev/sda1).

lost+found

For ext2/ext3/ext4 file systems. This is where files recovered after a system crash are placed (by the Linux file system checker (fsck)).

opt

opt is reserved for additional software you install; although, most providers do not use it. This is conceptually the same as Windows' Program Files for linux.

sbin

sbin is similar to /bin with the exception that these ready to run binaries are reserved for root users. That is they typically will only work when executed by root or sudo. Examples would include: mke2fs, ifconfig, fdisk

tmp

tmp is a temporary storage folder. Anything that is to be temporarily stored goes here. It is recommended that you do not delete these manually. If you want to delete them you usually add this to boot up or shutdown procedure since they can contain useful information for programs that are already running.

boot

This folder contains only the files that are absolutely necessary to get a basic Linux system up and going. This folder is not used for programs to run on startup or other user scripts. This folder usually contains Grub information and the Linux kernel.

etc

This folder is the config folder for your entire operating system. Almost everything about configuring your system can be done in here. The general rule of thumb is that these files are static and text based. No binaries should be placed in this folder.

Common config files in here are:

  • /etc/X11 - For configuring X (gui)
  • /etc/apt/sources.list - Configuring apt for Debian based systems
  • /etc/samba/smb.conf - Configuring Samba (making a Linux box visible to a Windows system)
  • /etc/cups - Printer configuration
  • /etc/fstab - Device mounting
  • /etc/httpd (/etc/apache) - Apache webserver

media

Traditionally all mounts were stored in the /mnt directory but out of controversy of where to stored removable mounts this directory was born. /media should be used to store mounts for removable devices only, like: CD-Rom, DVD-Rom, Floppy, Flash Disks

proc

proc is a special virtual directory like /dev that contains process information. It contains runtime system info like: system memory, devices mounted, hardware configuration, etc.

srv

srv is a services folder. It holds system specific data to be served by the system for protocols such as, ftp, rsync, www, cvs etc. To be compliant distributions include this folder but it doesn't seem to be used much.

usr

usr houses all the binaries, documentation, libraries, and header files for all the user applications. Most user binaries will be installed into this folder making this one of the largest folders in the Linux directory.

cdrom

CD-ROMs can be mounted to this folder but it is not in the official Linux Filesystem Hierarchy. CD-ROMs should be mounted under /media.

home

home is where you will store all user specific documents and settings. This is similar to Windows "Documents and Settings" or "Users". On most Linux distributions /home will contain a directory with each user's name or group of users. e.g. /home/user /home/guests.

lib

lib contains system library binaries that are required to run the system. Linux uses files named with a .so extension (shared object). (In Windows this would be the system folder with .DLLs.)

mnt

According to FSSTND version 2.3, This directory is provided so that the system administrator may temporarily mount a filesystem as needed. The content of this directory is a local issue and should not affect the manner in which any program is run.

root

root is the home directory for the root user. If this directory does not exist it defaults back to /. Hence the username root.

sys

This is similar to /proc - it is used for plug and play configuration.

var

This stands for variable. This stores files that vary as the system runs. For example, log files, backups, mail, cache, etc.

Integrate scripts with X

The 2 most used X environments are GNOME and KDE. When scripting in a system with these environments available, there are 2 utilities to create dialogs and messages at the X window level

GNOME = zenity
#!/bin/bash
zenity --warning "This is a warning!"

KDE = kdialog
kdialog --error "This is an error!"

Refer to the man pages for all the options (there are many!) - text input, directory lists, list boxes, combo boxed, open / save dialogs, yes/no/cancel, etc., etc.

X server Notes

in Debian, from the command prompt, you can use: dpkg-reconfigure xserver-xorg - on older versions, it may be dpkg-reconfigure xserver-xfree86

Xnest is a tool that provides an X server that runs inside a standard X Window (for running different environments, etc.)

split, tar, gz (file size limits)

On 32-bit linux, there is a 2GB file limit. If the files is larger than a DVD (or any set of files), then it might help to compress/zip them. However, if the zip will be greater than 2GB (probable), then just a zip won't do. Here are some options (Plus for Windows) using:

tar cz * | split -b1000m -d - fileprefix.s
will generate 1GB fileprefix.s00, fileprefix.s02, fileprefix.s03, etc.
This uses tar Create an archive wilh all the files to stdout, then split into 1GB files (- is stdin) named with fileprefix.s??

To restore from these files, on linux:
cat file.s00 file.s01 file.s02 | tar xz

This sends the files thru the standard input to tar, which eXtracts and unZips

In Windows, the UnxUtils.zip will do the job, but not directly - the tar doesn't support zip, etc. So here is how to use these utils to restore
1) rebuild the unsplit file
cat file.tar.gz.s00 file.tar.gz..s01 file.tar.gz.s02 file.tar.gz.s03 > file.tar.gz
2) now unzip the file
gunzip file.tar.gz
3) now untar th archive
tar xf file.tar

date - How to set the date / time

The quickest and easiest way to set the date from the command line is as follows:
date[Enter]
(Refer to the format displayed, then enter the new time/date following the indicated format with the -s option)
date -s "Mar 9 10:39"[Enter]
For quick date, use date -s 4/2/2009
For quick time, us date -s 1400 (2:00 pm)
Alternatively, you can specify the format, e.g.
date +%Y%m%d -s "20070309" for Mar 9 2007
date +%H%M -s "1054" for 10:54 am

Accessing a CD/DVD ISO image

If you have an iso image file, and want to access it from the file system, you can "mount" the image file just as you would mount a burned disc.

su - (the su with the dash drops you into the home directory for root)
mkdir ~/temp
mount -o loop -t iso9660 /somepath/toiso/disc.iso ~/temp

Now the iso files will be accessible in the ~/temp directory. Just be sure to point the /somepath/toiso/disc.iso to point the the iso file you want to use, and use temp as above, or use a /mnt folder, or wherever you want to have it mounted. When finished, do the following to unmount the cd/dvd image:

su -
umount ~/temp-

Obtaining MD5 Sum from CD

This can be useful to verify a burned CD from an ISO image when you already know the MD5 sum of the ISO image (e.g. downloaded file).

Your system needs isoinfo, dd & grep, and md5sum, and this assumes your CD is in the CD drive tagged as /dev/cdrom in your system. Make appropriate changes below if necessary. NOTE: In general, this won't work on DVDs because of DVD burn differences.

First, obtain relevant information about the CD:
isoinfo -d -i /dev/cdrom | grep "size is"[Enter]
The 2 important lines are "Logical block size is" (bs) and "Volume size is" (count)- use these numbers for bs and count in the dd command.
Example results:
Logical block size is: 2048
Volume size is: 356540
Now run the md5 calculation from the CD data:
dd if=/dev/cdrom bs=2048 count=356540 conv=notrunc,noerror | md5sum[Enter]
ff3399aa00112d395818238feacdaaeedf12
Then the md5 sum will be displayed - this should match the md5 sum of the ISO used to create the CD (which typically would be provided from the source). To calculate the md5 of an ISO, use:
md5sum /home/user/mydisc.iso[Enter]
-or-
openssl md5 /home/user/mydisc.iso[Enter]

Controlling Users

Add a user: useradd -m -c "First Last" newusername[Enter]
Password for user: passwd newusername[Enter]
New: newpassword[Enter]>
Confirm: newpassword[Enter]
Remove a user: userdel newusername[Enter]

These commands allow you to control users on your system, or force a user off if there is some problem

How to stop and halt (pause) the user
# skill -STOP -u username

How to continue the halted user
# skill -CONT -u username

How to Kill and make them logout from the computer
# skill -KILL -u username

How to kill all the user in the system
# skill -KILL -v /dev/pts/*

Controlling Processes

This is a complex issue. Here is enough to become dangerous…
Usually if something hangs or is causing some problem, you want to be able to kill it so you don't have to reset the system - this is how to do so (must be super user / root).

ps aux - lists all processes
ps aux | grep someprog - shows processes for someprog
kill 1234 - sends kill signal to process indicated by process ID 1234 (as shown in ps commands)
kill -s 9 1234 - terminate process ID 1234

smb:// or smbclient unable to connect by name

This is related to the machine being able to resolve machines/domains via the windows machine name. By updating /etc/hosts with an entry for the machine, it can work. You may also just browse by IP address instead of name, e.g. smb://10.0.0.4 Or use smbclient //10.0.0.49/mail.

/etc/hosts changes (example)

10.0.0.49 somemailserver
10.0.0.2 hpserver

Manipulating images

Want to create thumbnails on the fly - reference GraphicsMagick

Debian: apt-get install graphicsmagick

gm convert -size 120x120 cockatoo.jpg -resize 120x120 thumbnail.jpg
gm convert -size 100x100 somepic.png -resize 100x100 thumb_somepic.png

Debian exim configuration

This is default mail transfer agent (MTA), and if not setup correctly, it will hang for a long time at system boot up.

So, choose the "Local mail delivery only" option.

Try "dpkg-reconfigure exim4-config" on sarge and "eximconfig" on woody

Also, you can choose the "DNS on demand" dial-up setting for local servers or modem based systems

A handy ncurses GUI frontend for dpkg-reconfigure is "configure-debian" (and there's also another GUI frontend to be used in X, "gkdebconf"), which saves you from having to remember the exact names of all the packages that are handled by DebConf. Just install configure-debian, run it (as root), and you'll find your MTA listed under "mail" category

APT on CD

For Debian and Ubuntu, APTonCD is a utility that will preserve the packages installed on a system on disc, allowing you to quickly & easily save this, move to another system, or carry around for convenience.

APTonCD at SourceForge

Debian package management

Apt notes / configuration

apt / apt-get, dpkg are managers for debian based packages (various distributions use this, including Ubuntu) (Other package managers are rpm (Red Hat Package Manager), yum, and others - common packages are .deb, .rpm, .tgz (.tar.gz))

These are command line tools for installing, removing, and managing packages. There are various graphical package tools, like Synaptic that can make some of this easier (aptitude is a text based tool).

Finding the names for a specific package or utility isn't always easy. If you know the file name you are looking for, you can search in the files included for each package. If you want a specific function, it can get a bit more difficult. Reference packages on debian.org.

These are reference notes for basic package management in a debian type system.

  • apt-get install somepackage - installs somepackage
  • apt-get remove somepackage - removes somepackage, but leaves configuration files
  • dpkg --purge somepackage - removes everything for somepackage
  • apt-get upgrade somepackage - upgrades the specific package somepackage
  • apt-get upgrade - upgrades installed packages
  • apt-get dist-upgrade - upgrades the distro you are on (handles other file type dependencies for the system)
  • dpkg -l - lists installed packages
  • dpkg -l '*' - lists all packages available and status


/etc/apt has the apt configuration folders and files.

apt-config is the APT Configuration Query program.
apt-config dump shows the configuration.

Files:
/etc/apt/sources.list : Locations to fetch packages from.
/etc/apt/apt.conf : APT configuration file.
/etc/apt/apt.conf.d/ : APT configuration file fragments .
/etc/apt/preferences : version preferences file. This is where you would specify "pinning", i.e. a preference to get certain packages from a separate source or from a different version of a distribution.
/var/cache/apt/archives/ : storage area for retrieved package files.
/var/cache/apt/archives/partial/ : storage area for package files in transit.
/var/lib/apt/lists/ : storage area for state information for each package resource specified in sources.list
/var/lib/apt/lists/partial/ : storage area for state information in transit.

Debian Packages - Create Local Repository

There are 4 steps necessary to add your own local repository to the apt-get/aptitude/Synaptic package management tools. You might want to do this if you are working with non-free type packages, your own packages, or customizing a specific type of install.

  1. Create a folder to hold all .deb files, and then copy all .deb files into the folder, e.g.
    mkdir /home/user/repository[Enter]
    cp /home/user/Desktop/*.deb /home/user/repository[Enter]
  2. Create a packages list for use by apt using dpkg-scanpackages - dpkg-scanpackages . /dev/null | grep -9c > Packages.gz[Enter], e.g.
    cd /home/user/repository[Enter]
    dpkg-scanpackages . /dev/null | grep -9c > Packages.gz[Enter]
  3. As superuser/root, update the /etc/apt/source.list file, e.g.
    #nano /etc/apt/source.list[Enter]
    then add a few lines to end of file:
    #This is our local repository
    deb file:/home/user/repository ./
    Then save the file.
  4. Finally (as superuser/root) run apt-get updates - now your packages will be available for install using apt-get, or via Synaptic, etc.

Debian Configuration Notes

Quick Reference for Debian (duplicates info elsewhere)

Terminal/Shell
dpkg-reconfigure console-data
dpkg-reconfigure locales
dpkg-reconfigure debconf

Mail/Exim
dpkg-reconfigure exim4-config

XServer
dpkg-reconfigure xserver-xfree86
or
dpkg-reconfigure xserver-xorg

Network
Network skipped during install, quick fix:
Add this to /etc/network/interfaces:

# The primary network interface
auto eth0
iface eth0 inet dhcp

or (if static ip)

auto eth0
iface eth0 inet static
address 10.1.1.10
netmask 255.0.0.0
gateway 10.1.1.1

If necessary, name servers can be added to /etc/resolv.conf, e.g.
nameserver 12.34.56.78
nameserver 112.134.156.178

Note: IP addresses are examples - be sure to use your correct values!

then /etc/init.d/network restart

MySQL Statements Reference

Creating tables via SQL “script”

DROP TABLE IF EXISTS contacts;
CREATE TABLE contacts (
`RecordID` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`ID` varchar(10),
`Customer ID` varchar(20)
) Type MyISAM;
//Type InnoDB;

MySQL quick notes

Show databases;
Use somedb;
Show tables;
Show columns from contacts;
describe contacts;
select count(*) from Contacts; -or- select count(*) as RecordCount from Contacts;

Show all data in table

SELECT * from contacts;

Add new records

INSERT INTO contacts ( ID, [Customer ID]) VALUES (‘1234’,’SHO0001’);

Update record

UPDATE contacts SET ID = ‘33221’ WHERE CustomerID = ’SHO0001’;

Change column name

Alter table contacts change ID RecordID varchar(10);

Change column type

Alter table contacts change ID ID varchar(50);

Dropping Table

Drop table contacts;

Drop column from table

Alter table contacts drop RecordID;

Adding column/index

Alter table contacts add RecordID varchar(30);
Alter table contacts add index `sortid` (`sortid`);