|
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:
- Linux From Scratch - Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own customized Linux system entirely from source.
- OSAlt.com - Open Source Alternatives to well-known commercial software
- SourceForge.net - thousands of software projects
- VirtualBox.org - Open Source, GPL virtual machine solution
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, fromdos, iconv | | 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 | | Sound & Video | | Manipulating mail box files | | Debian exim configuration | | APT on CD | | Postfix | | DNS Tools | | Debian package management | | Debian Packages - Create Local Repository | | Debian Configuration Notes | | Mouse Configuration | | MySQL Statements Reference | | |
The Beginning - Boot sequence summary
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.
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)
- 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
- 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
- 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.
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
- 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)
- 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:
- 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, fromdos, iconv
Command reference, system manual, info pages, conversion utilities
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)
fromdos - converts DOS/Windows based text files into Unix files, e.g. CR-LF to LF line delimiters. (apt-get install tofrodos)
todos - converst Unix files to DOS/Windows text files, e.g. LF to CR-LF line delimiters
CR is carriage return, ASCII control character 13, used to return text caret to beginning of line, LF is Line Feed, ASCII control character 10, used to move down a line. For certain older printers, the dual CR-LF was required so the next line would start at the beginning (vs. immediately below the last character of the previous line). Certain Web technologies chose CR-LF, while Unix went with the single LF character. However, for certain uses, the assumption had to be made that LF also meant go to the beginning of the line, to save lots of bytes in large files (not needing the extra CR byte).
iconv -f UTF-16 -t ASCII//TRANSLIT//IGNORE unicode.txt > ascii.txt - iconv will convert between various formats - see man iconv - the above can be used to convert Windows Unicode Text files to something a bit more useful in Linux 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
Debian Squeeze - to recreate the xorg.conf, without the x-server running, use Xorg -configure
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 to create an archive with 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
To split an existing archive into 1GB files (say for backing up on a DVD without running into 2GB file size limit - 4 files fit comfortably per DVD)
split -d -b1000M archive_2013_03_18.tar.gz archive_2013_03_18.tar.gz.s
So a 9GB file will make .s00, .s01, .s02 --- .s08 files, e.g. archive_2013_03_18.tar.gz.s00
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]
Add existing user to an existing group: usermod -G groupname username[Enter]
Add a user with specific directory (here /home/ftp) as home: useradd -m -d /home/ftp -c "First Last" 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
Sound & Video
Sound and Video is extremely large topic - this is for some people who are trying to do something, but don't know where to start. Just some basic info and a particular starting point for various categories.
Sound
Speakers - way to test speakers from command line:
Examples:
speaker-test -t sine -f 1000 -c 2 -s 1 &
speaker-test -t sine -f 1555 -c 2 -s 2 &
speaker-test -c 5 -l 1 -t wav &
alsa - sound library (there are others)
Some command line tools:
alsamixer
aplay soundsound.wav
Video
mplayer / mecoder
Huge number of options, command line examples:
mplayer SomeVideo.m4v
mplayer SomeVideo.avi
Convert from one Video format to another (with options)
mencoder SomeVideo.m4v -o SomeVideo.avi -oac pcm -ovc lavc -lavcopts vcodec=wmv1
Media Player
Audio: Amarok, Rhythmbox, Kaffiene, JuK
Video: VLC, Dragon Player, mplayer
DVD ripper/video converters
You never know when you'll have to get that family video onto a website...
Rip: HandBrake, Thoggen DVD ripper
converter: VLC, WinFF, ffmpeg
Disc burner
K3B, Brasero
mkisofs, cdrecord
WebCam/Camera/Tuner access
xawtv, video4linux
/usr/bin xawtv -hwscan
#/home/user/.xawtv has config settings
/usr/bin/xawtv -device /dev/video0 &
v4l-conf
v4l-info
Open a web cam on the secondary display
#!/bin/bash
DISPLAY=:0.1
/usr/bin/mplayer tv:// -tv driver=v4l2:width=400:height=300:device=/dev/v4l/by-id/usb-Vimicro_Corp._PC_Camera-video-index0 &
Video Editors
OpenShot, Blender, Cinelerra, kdenlive
Video Renderer
Blender
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
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. DNS Tools
DNS stands for Domain Name System, sometimes just referred to as nameserver(s). /etc/resolv.conf shows name servers to be queried to resolve a domain name for mail, ping, etc. utilities. For example, when you type ping linuxcollections.com[Enter], the sequence to ping the server starts with trying to resolve the IP address for linuxcollections.com - by referencing the /etc/resolv.conf file, the name servers listed can be used to find out what address should be used by the TCP/IP protocol layer to communicate with.
ping linuxcollections.com[Enter] verifies name server lookups are working
nstools[Enter] interactive tool to display name server or ip lookups
nstools goes into a > prompt - type the domain name to see response, and type the IP address to see the reverse DNS result
dig[Enter] command line tool to display name server records for a domain (e.g. A or MX entries)
type dig mymaildomain.com[Enter] to see basic entries (A), or use dig mymaildomain.com MX[Enter] to see Mail Exchanger entries
telnet mymaildomain.com 25[Enter] telnet is an interactive communication tool - here, can be used to verify a mail server is responding - 587 is becoming a more common port, e.g. telnet mymaildomain.com 587[Enter]
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.
- 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]
- 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]
- 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.
- 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
or
Xorg -configure
or
modify /etc/X11/xorg.conf
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
Mouse Configuration
Background: Had problems with an old ball mouse, so bought a Logitech Optical Mouse PS/2 (model M-SBF96), and plugged it in to the KVM, rebooted, and the mouse went crazy wild. Many hours later, this was the solution.
Debian Squeeze, kernel 2.6.32-5-amd64. Started with the xserver-xorg settings, but that was a dead end. Needed to update/override the mouse driver options (specifically the driver protocol). Verified that without the psmous.conf file, the mouse did not work. Believe the proto=bare was key piece, but this was not verified (other proto settings did not work). Here is approach:
Created /etc/modprobe.d/psmous.conf file with these settings
options psmouse proto=bare rate=60 resolution=200 smartscroll=Y
Notes: Saw other notes that this file is psmouse.conf - did not check to see if it matters, but used psmous.conf Played with resolution, not sure how sensitive/important this value is here Also not sure how important rate and smartscroll are Other entries for proto resulted in unusable mouse Mouse wheel still not working - not sure if bare entry is cause Run xev from terminal to see raw mouse events 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`);
|