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:

Reference and resource links:


The Beginning - Boot sequence summary      Boot loaders
fdisk notes      fsck notes
file basics - cp, mv, rename      utility basics - man, info, ps2pdf
utility basics - sed, grep      utility basics - find, which, whoami
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
passwd notes      Controlling Processes
smb:// or smbclient unable to connect by name      Manipulating images
Manipulating mail box files      Debian exim configuration
APT on CD      Debian package management
Debian Packages - Create Local Repository      Debian Configuration Notes
MySQL Statements Reference      Postfix

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.

file basics - cp, mv, rename

To Copy a file, use cp ExistingFileName NewFileName[Enter]
To Move or Rename a single file, use mv ExistingFileName NewFileName[Enter]
To rename multiple files (on Linux) use rename ExistingNamePart NewNamePart Files, e.g. rename .c .cpp *.c[Enter]
For more on rename man rename

Examples

Copy foo.txt to foo.bar:
cp foo.txt foo.bar[Enter]

Copy foo.txt to foo.bar with folders:
cp /tmp/foo.txt /home/user/Desktop/foo.bar[Enter]

Copy folder and all its files:
cp -R /home/groupleader/data /home/user/Desktop/data[Enter]

Move (Rename single file) foo.txt to foo.bar:
mv foo.txt foo.bar[Enter]

Rename all .txt files to .c files:
rename .txt .c *.txt[Enter]

Do something fancy with a bunch of files (bash script) - prepend header.c to text files and rename to .c using base file name:
vim script.sh[Enter] -or- nano script.sh[Enter]
#!/bin/bash
#add header & rename files
for item in `ls *.txt`
do
  #fancy bash syntax to get filename without extension
  $newitem="${item%.*}"
  cat header.c $item > $newitem".c"
done
## Note if you have long file names with spaces, the for loop also marches through parts of the file name. Since this isn't what you want, you can do this:
ls *.txt | while read item;
do
  #use sed to strip out file extension
  newitem=`echo "$lineitem" | sed -e 's/.txt//'`
  cat header.c $item > $newitem".c"
done
[Save file]

Change script to be executable:
chmod 755 script.sh[Enter]
-or- chmod +x script.sh[Enter]
Then run the script:
./script.sh[Enter]

utility basics - man, info, ps2pdf

Command reference, system manual, info pages

man = manual pages command, used to look up reference & details on system commands, system calls, etc., anything documented
Examples:
man grep[Enter] displays the options and overview of the grep command
man sed[Enter] displays the options and overview of the sed command

info = info pages - the GNU update/improvement to man - man is the original UNIX command for the manual, info is a GNU system preferred replacement. In practice, often man and info essentially display the same things, however (dependent on the system and command), there may be differences.
Using the ps2pdf utility, you can easily create PDF documents for specific commands - which may make it easier to print/save/view:

ps2pdf = outputs postscript to PDF format
man -t grep | ps2pdf - grep.pdf[Enter] outputs the man page to postscript (-t = default formatter groff for postscript) which is then piped into the ps2pdf utility (postscript to pdf) using stdin as input (-) and the output file specified (here, grep.pdf)

utility basics - sed, grep

Lots of capabilities, these are just some useful basics

sed = stream editor. Conceptually this streams text through a filter, and you can make changes or perform operations on the text as it goes by. Most common usage would be to search and replace, either first occurrence, or globally.
Take a file and replace first occurrence of some text ("OldValue") with something else ("NewValue"):
cat myfile.txt | sed -e 's/OldValue/NewValue/g' > mynewfile.txt[Enter]
Explanation: cat outputs myfile.txt to standard output, which is pipelined (filtered) through sed. The -e (expression, or 'edit script') option says use the script command given to perform your operation. The s///g syntax says search for the first value (between slashes), and replace with the second value. Output is modified text. This is redirected to a new file called mynewfile.txt. So mynewfile.txt gets the modified version of myfile.txt (which is left intact in this example). The g ensures the operation is global, or for every pattern matched - this is a basic global search and replace using sed.

grep = line matching (prints lines matching pattern). Conceptually this streams text through a filter, and will print (echo back) any line that has a match of pattern.
Take a file and find all lines with ("OldValue"):
cat myfile.txt | grep OldValue > mynewfile.txt[Enter]
Explanation: Only lines that have the OldValue text in them will be placed in new file mynewfile.txt.
cat myfile.txt | grep -i OldValue > mynewfile.txt[Enter]
Explanation: (-i option - case Insensitive) Only lines that have the OldValue text (case Insensitive search, i.e matching text, case does not matter) in them will be placed in new file mynewfile.txt.
cat myfile.txt | grep -c OldValue[Enter]
Explanation: (-c option - count option) Only lines that have the OldValue text in them will be counted - result will be a number, e.g. 0, 12, 44, etc.
grep can be useful for working with logs, e.g. a mail.log: cat mail.log | grep emailtoyou@example.com[Enter]
Explanation: This will filter log and show any mail events for the e-mail address specified.

utility basics - find, which, whoami

find = multi-faceted utility that can find files

find always wants a path first, followed by options

Find a specific file (missinglib.so) somewhere on the system:
find / -name missinglib.so[Enter]

Find a certain files (QuarterlyReport*.*) in the home area:
find /home -name QuarterlyReport*.*[Enter]

Find all files larger than 500M and less than 1GB:
find / -type f -size +500M -size -1G

which = utility to locate commands / find executable files

Examples:
which grep[Enter] - shows /bin/grep
which which[Enter] - shows /usr/bin/which

whoami = shows current user. This can be useful especially for remote users and system administrators.

whoami[Enter] - shows current logged on user

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.)

xwininfo is a tool that provides window info on the command line

Use xwininfo -root -tree[Enter] to list all windows, child windows, etc. currently on the system within X

xprop is a tool that provides property info for X objects on the command line

Use xprop[Enter] then click on a window to display its properties

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/*

passwd notes

passwd changes your (or (if you are root/superuser) another user's) password.

passwd[Enter]
Will ask for current password, new password, then retype new password (to verify) - if all is correct, it will update and change your password (or indicate a problem if one occurs).

as root/superuser
passwd someuser[Enter]
Will ask for new password, then retype new password (to verify) - if all is correct, it will update and change someuser's password.

A few passwd options:
-d, --delete, e.g. passwd -d someuser[Enter] - Delete a user's password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless.
-S, --status, e.g. passwd -S someuser[Enter] - Display account status information. The status information consists of 7 fields. The first field is the user's login name. The second field indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age, maximum age, warning period, and inactivity period for the password. These ages are expressed in days.

Kerberos problem?
If this is on a new Debian (or other) system, and you get “Enter Kerberos password”, and you don't need/want Kerberos, you can remove the security library with:
apt-get purge libpam-krb5[Enter]

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

Manipulating mail box files

mbox type files are single files that concatenate messages separated by each other with a From[space] format line. Ignoring the details - see Wikipedia mbox for background - if you want to split this file into separate text files, the formail utility can help

Assume your mailbox file (mbox) is found in /var/mail/user (where user is the user who's mail you want to access). Have root (or sufficient rights user) copy the file into your home directory, i.e. cp /var/mail/user /home/user/mbox.txt[Enter], and perform the following steps:

mkdir mailfiles[Enter]
cp mbox.txt mailfiles
cd mailfiles[Enter]
cat mbox.txt | formail -ds sh -c 'cat > msg.$FILENO.txt'[Enter]

The above will split each mail message into msg.000.txt, msg.001.txt, etc.

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 update - 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`);

Postfix

Running postfix, and you need to delete a group of mail messages from a mail queue (e.g. a mail script gone bad, or a domain not accepting mail, etc.)

Here is a combination command that will delete a group of messages from the queue - it dumps the mail queue, strips out the messages of interest, obtains the mail ID, and finally ask postsuper (postfix administration command tool) to delete them.

mailq | grep advertmail@ | cut -f 1 -d ' ' | postsuper -d -
-or-
mailq | grep advertmail@ | awk '{print substr($1,1,10)}' | postsuper -d -

Command explained:
The commands are piped through each other using the | (pipe) symbol - this means the output of the first is fed as input to the second, the output of the second is fed as input to the third, etc.
mailq - this is the command that lists the mail queue, or items waiting to be mailed. This lists various details about each mail item.
grep advertmail@ - after this command is processed, it will only show the first line of the mail queue command for the mail items of interest. In this example, advertmail@ is the user that has sent the mail we want to delete. You might use a domain, e.g. "grep yahoo.com" to list mail going to the yahoo.com domain. You will want to use the correct text for the mail items of interest, and test at this point (i.e. mailq | grep someuser[Enter] to verify you are listing the mail items you want to delete).
cut -f 1 -d ' ' - this item "cuts" the first field [-f 1] (delimited by space, e.g. a [-d ' '] (single-quote,space,single-quote)), which is the mail ID. The awk approach [awk '{print substr($1,1,10)}'] is more exacting, but it helps if you are familiar with awk syntax - in this example, it takes the text of each line, and outputs the first 10 characters (in this case, the mail ID is 10 characters).
postsuper -d - - finally, the postsuper command has various options, and the -d option is to delete the mail (by ID). In this case the trailing -, means to take the input from the standard input (vs. a file or via command line).

When testing, build up the command by testing mailq and grep portions, then add the "ID stripping" command of cut or awk, before finally using the full command that will delete the mail items. If you build step-by-step, the last command (before postsuper) will show a line by line listing of mail IDs.