Thursday, December 13, 2007

using screen as a terminal

from duane's pclug 14 slides at http://duane.freeshell.net/pclug/meeting_0014/slide_04.html


All screen commands start with the keystroke CTRL-a. We'll learn the most important one first CTRL-a ? This shows us the keystroke reference for screen. Now we'll list the open windows with CTRL-a w. We see that we only have one window open. Let's fix that by creating a new window with CTRL-a c. Now CTRL-a w shows us windows 0 and 1. To switch back to the first window, we use CTRL-a 0.



Thursday, November 8, 2007

Using a torrent to download from the command line

i was trying to download the dvd iso images of the debian distro. i downloaded the torrent files to the directory /data/iso/debian using the firefox browser. then i used btlaunchmany to actually download the iso images. i used the following command

btlaunchmany /data/iso/debian --max_upload_rate 5

/data/iso/debian is the directory that contains the torrent files
--max_upload_rate limits the rate at which packets can be uploaded from your machine


i didn't realize it when i started this process, but the bittorrent-downloader man page describes a --url option that downloads the torrent info file.

Burn content to a DVD

use aptitude or apt-get to verify that you have dvd+rw-tools installed.

use the following command

growisofs -dvd-compat -input-charset=ISO-8859-1 -Z /dev/hda -R -J -pad "/my/directory/datas"


/dev/hda is the dvd burner device
/my/directory/datas is the path to the content to be burned

How to format a DVD-RW

use aptitude or apt-get to verify that you have dvd+rw-tools installed.

use the following command

dvd+rw-format -force /dev/hda

/dev/hda is the dvd burner device

Burn iso to a DVD from the Command Line

use aptitude or apt-get to verify that you have dvd+rw-tools installed.

use the following command

growisofs -dvd-compat -Z /dev/hda=/path/to/image.iso

/dev/hda is the dvd burner device
/path/to/image.iso is the iso file to burn

Thursday, October 4, 2007

using sed to edit a string in a file

action:
use sed to change a windows path 'g:\\' to a unix path '/share/data' in a file

command:
sed -e 's/g:/\/share\/data/g' -e 's/\\\\/\//g' file.2

comment:
sed == is a stream editor that can be used from the command line
format is - sed [command] <[inputfile]>[outputfile]
-e == is followed by a command, in this case a regex
< == is the input file
> == is the output file

vi keybindings for xpdf

Here is how to enable vi keybindings for xpdf navigation (j for up, k for down, h for left, l for right).

Add the following line to your ~/.Xresouces file.

xpdf.viKeys: true
Then run xrdb to load the changes:
xrdb ~/.Xresouces


source: http://linuxwisdom.blogspot.com/search?q=xpdf

Wednesday, September 19, 2007

vga boot modes

i found the following info when trying to change the screen resolution at the command line (http://www.pendrivelinux.com/2007/05/24/
vga-boot-modes-to-set-screen-resolution/).


VGA Resolution and Color Depth reference Chart:
Depth 800×600 1024×768 1152×864 1280×1024 1600×1200
8 bit vga=771 vga=773 vga=353 vga=775 vga=796
16 bit vga=788 vga=791 vga=355 vga=794 vga=798
24 bit vga=789 vga=792
vga=795 vga=799

Friday, August 24, 2007

date format

date +%F\@%H%M

will display

2007-08-24@1439

vim keystrokes

1. Shift-k displays man page
place the cursor on a unix command word and press Shift-k
the man page for the command will be displayed

Thursday, August 23, 2007

file diff using vim

starting diff mode

vimdiff file1 file2 or vim -d file1 file2


while already in vim you can start diff mode in three ways.

:diffsplit {filename} - open a new window on the file {filename}
:diffthis - make the current window part of the diff windows
:diffpatch {patchfile} - use the current buffer, patch it with the diff found in {patchfile} and open a bufer on the result



jumping to diffs

[c - jump backwards to the previous start of a change
]c - jump forwards to the next start of a change



diff copying

:[range]diffg[et] - modify the current buffer to undo difference with another buffer
:[range]diffpu[t] - modify another buffer to undo difference with the current buffer
do - same as ":diffget" without argument or range. the "o" stands for "obtain"
dp - same as ":diffput" without the argument or range

when no [range] is given, the diff at the cursor position or just above it is affectes.

Wednesday, August 22, 2007

find and overwrite a file

i had a need to find all files of a certain name, 'file1.file' and a certain size, greater than 20k, and overwrite every occurence with a different file 'file2.file'.

find ./ -type f -iname 'file1.file' -size +20k -exec cp ~/trunk/file2.file '{}' \;
./ == start find from the current directory
-type f == search for files
-iname 'file1.file' == insensitive case of the file named file1.file
-size +20k == search for files 20k in size or greater
-exec cp ~/trunk/file2.file '{}' \; == for each file found in the find, copy ~/trunk/file2.file and overwrite

Tuesday, August 21, 2007

initial postgres login

i recently installed postgres 8.1 on my debian system using aptitude. following are the steps i used to create a new database or user.

1. su to super user
2. su to postgres user
3. create a new database or user

for more follow http://blog.revsys.com/2007/05/common_postgres.html

Tuesday, August 7, 2007

audio and usb on winxp vm in virtualbox

below is what i did on my debian box to get audio and usb to work on my winxp vm in virtualbox. i would expect this to work just fine on ubuntu also.


audio

open the innotek virtualbox program
choose the winxp vm and click the settings button for the vm
select audio in the left hand menu
select enable audio
select host audio driver to be ALSA audio driver


usb

execute the following command from the command line as root and add the following command to your /etc/rc.local file

chown -R root:vboxuers /proc/bus/usb


add to following line to the bottom of /etc/fstab

none /proc/bus/usb usbfs devgid=1003,devmode=666 0 0


then execute "mount -a" from the command line as root


start winxp vm

then put a usb thumb drive in a usb port and start a winxp vm in virtualbox
you should be able to here all the cool windows startup sounds ;^)
you should also be able to access any usb device

Tuesday, July 10, 2007

steps to compile a debian kernel

DebianKernelCompileSteps

These following steps to compile a Linux kernel for Debian are taken from steps published on the web by Falko Timme [at] falkotimme [dot] com. I modified his steps for grub. He originally used lilo.


Be aware that there is some risk in compiling your own kernel! For example, it could happen that your machine does not boot properly after you have installed the new kernel so you might be forced to boot from a rescue CD to repair your system. You have been warned! This document comes without warranty of any kind!



Prepare Your Current Machine


First login to your Debian machine on the command line as root. Install the prerequisites that we need to compile and run a new kernel. At the command line execute the following:

apt-get update
apt-get install kernel-package ncurses-dev fakeroot wget bzip2 module-init-tools initrd-tools procps

If you are asked the following question:

"If you really want to remove modutils type 'yes':"

type yes.

It might also be necessary to update packages like bind9, quota, etc. - depending on your configuration. If you have problems with your existing packages try to get the appropriate package from www.backports.org.



Get the Kernel Source


Then go to /usr/src:

cd /usr/src

Then get the latest Linux kernel source (or the kernel source you need) from http://www.kernel.org/pub/linux/kernel/v2.6/:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.8.1.tar.bz2



Unpack the kernel sources:


tar xjf linux-2.6.8.1.tar.bz2

cd linux-2.6.8.1/



Configure the Kernel


It is normally a good idea to take the configuration of your existing (working!) kernel 2.6 as a starting point for the configuration of your new kernel. Usually the current kernel configuration is saved in a file under /boot, e.g. /boot/config-2.6.3. We will load this configuration and then do the changes we desire.

make menuconfig

Select Load an Alternate Configuration File and enter the location of the configuration file of your current kernel (or upload my kernel configuration to your machine and enter its path):

The configuration of your current kernel will be loaded, and you can now browse through the menu and change the configuration to suit your needs. When you are finished, save your new kernel configuration:

Then run the following commands (please note that make dep is not needed any more for kernel 2.6):

make-kpkg clean
fakeroot make-kpkg --revision=custom.1.0 kernel_image


If the compilation stops with an error, run

make clean

and then re-run the previous commands starting with

make menuconfig

Change the kernel configuration where the error occurs. If no error occurs you will find the new kernel as a Debian package called kernel-image-2.6.8.1_custom.1.0_i386.deb under /usr/src.

cd ../



Install Your New Kernel


dpkg -i kernel-image-2.6.8.1_custom.1.0_i386.deb

Create a ramdisk of your new kernel (otherwise your system will most likely not boot):

cd /boot/
mkinitrd -o /boot/initrd.img-2.6.8.1 2.6.8.1



Edit Grub List


We are almost finished now. Edit the Grub stanza in /boot/grub/menu.list and add the line initrd /boot/initrd.img-2.6.8.1.

title Debian GNU/Linux, kernel 2.6.8.1
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1 root=/dev/hda1 ro
initrd /boot/initrd.img-2.6.8.1
savedefault

title Debian GNU/Linux, kernel 2.6.8.1 (single-user mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1
savedefault


Reboot Your Machine

reboot

and if everything is ok your machine should come up with the new kernel. You can run

uname -a

to verify that. Good luck!

faster debian booting

to speed up my debian booting, i have disabled the following services using the update-rc.d command:

postgresql
bittorrent
tomcat5
bluetooth
apache2
apache-perl

doing this should speed up my systems boot time and still give me access to these services when i choose to use them.

managing system services/daemons

on a debian system, the scripts to start and stop the system's services/daemons reside in /etc/init.d/ . For example, to stop the bittorrent service execute the following at the command line:

>/etc/init.d/bittorrent stop

to start the bittorrent service, execute the following at the command line:

>/etc/init.d/bittorrent start


what if the package apache2 is installed on my system, but i don't want that service to be started when the machine boots.

the command update-rc.d manages the links between the /etc/rc#.d directories and the scripts in the /etc/init.d directory. to enable a service on boot execute the following at the command line:

>update-rc.d "serviceName" defaults

to disable a service on boot execute the following at the command line:

>update-rc.d -f "serviceName" remove

Friday, June 29, 2007

synchronize files between laptop and usb disk

following is the command i used to synchronize music files on my laptop and external usb disk. /share/music/files/ is the path on my laptop.

rsync -avzC /share/music/files/ /media/usbdisk/music/files
-a == archive
-v == verbose
-z == use compression while transferring files
-C == exclude common CVS files and directories
trailing / on a path means to only copy the contents of that path

restart services after update

how do i know which services need to be restarted after a system update? in the package debian-goodies is a program named checkrestart. run this program as root and it will print out the daemons that need to be restarted.

allow a user to mount a usb drive

i wanted to use rsync ( a cool synchronization program) to keep the music files on my laptop and external usb disk in sync. the problem i ran into was that root was the only user that can mount and umount a drive. after mounting root would own all the files on the usb drive and i could not rsync my files without doing a chown recursively on the usbdisk or letting root own all of the music files on my computer.

after reading the man page on the mount command i found a line that reads: "Normally, only the superuser can mount file systems. However, when fstab contains the user option on a line, anybody can mount the corresponding system."

problem solved

Wednesday, June 27, 2007

keyboard shortcut to launch web browser

i want to use a keyboard shortcut to launch my web browser. i'm currently using Gnome on a Debian system. on the top panel choose Desktop -> Preferences -> Keyboard Shortcuts. in the keyboard shortcuts window, select Launch Web Browser and enter the desired key combination. i chose ctrl-alt-w as my key combo.

when i used my key combo the first time it launch a gnome web browser. i would prefer to use opera or firefox, so i needed to modify which browser the key combo fired off. after googling i discovered a mechanism called alternatives. this is basically a set of symbolic links divided into catagories that can be configured. if you execute update-alternatives --list gnome-www-browser you get  /usr/bin/firefox and /usr/bin/w3m printed out. you can modify which alternative is chosen.

there is a gnome gui version called galternatives. use apt-get or another package manager to install it. then execute galternatives from the command line as root. select a category in the left side pane and choose an alternative in the right side pane or a new alternative by providing the path of the executable. so i chose gnome-www- browser, clicked the add button and entered /usr/bin/opera. close out galternatives and press my key combo. now opera is launched with ctrl-alt-w.

synchronize usb drive with laptop in linux

below is the command i used to synchronize the contents of my usb thumbdrive with a shared directory on my computer

>rsync -Cavz --delete /media/usbdrive/ /share/syncDir/
     -C == excludes cvs directories
     -a == archive, preserves pretty much everything recursively
     -v == verbose
     -z == compresses data, only necessary when dealing
          with a remote connection
     --delete == deletes files at the destination that are not at the
          source, read man page for more control
     --dry-run == print result to stdout without actually executing
          the sync

how i fixed my no sound problem in Debian

i recently install Debian my laptop. i had trouble getting xmms to play sound. after much googling i had to install the appropriate alsa packages, execute alsaconf, and add my user to the audio group (adduser username audio). this seemed to do the trick.

Friday, June 22, 2007

Find a directory by name in linux

Command to find a directory by name in linux
>find /share/backup/ -type d -name '.svn' -ls
-type d == directory
-name '.svn' == all directories named .svn
-ls == converts unusual characters to C style escape sequences

To delete the list of directories returned by the above command execute
>find /share/backup/ -type d -name '.svn' | xargs /bin/rm -dr
xargs builds and executes command lines from standard input
/bin/rm -dr == remove command with the directory and recursive flags