Alternatives

System Debian ls /etc/alternatives update-alternatives --display x-www-browser sudo update-alternatives --config x-www-browser

Show data as hexdecimal format

shell * od -tx1 file.txt xxd file.txt hexdump file.txt

Install package without depencies

dpkg * dpkg --force-all -i [package] /var/lib/dpkg/status -Search broken package -Remove lines: Depends: Pre-Depends: Recommends: Suggests: Conflicts:

Make your own patch

Patch * diff -rupN a/ b/ > own.patch

How do I su to another user and run an X application?

Xorg * xhost +LOCAL:

Replace string in files

Shell * sed -i 's/string1/string2/g' file.txt sed -i 's/old-word/new-word/g' *.txt grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

WLAN by hand

Network * /etc/wpa_supplicant.conf # Simple case: WPA-PSK, PSK as an ASCII passphrase, allow all valid ciphers network={ ssid="simple" psk="very secret passphrase" priority=5 } # The higher the priority the sooner we are matched /etc/network/interfaces #auto wlan0 iface wlan0 inet dhcp up wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf down killall wpa_supplicant # Change Network Interface device name ip link set dev eth1 name wlan0

How to remove very broken packages

cd /var/lib/dpkg/info sudo rm flashplugin-nonfree.* sudo dpkg --remove --force-remove-reinstreq flashplugin-nonfree

Hexdump

Shell * xxd [file] echo "test" | xxd

Serial console

Console * /etc/inittab # Example how to put a getty on a serial line (for a terminal) # T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100 #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100 sudo init q /etc/issue (optional) Debian GNU/Linux 6.0 \n \l at \b bps (\U) /boot/grub/grub.conf # Everything to serial console: kernel /vmlinuz-2.4.20-24.9 ro root=LABEL=/ console=ttyS0,38400 Info: dmesg|grep tty [ 1.917029] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A [ 1.955642] 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A setserial -a -q /dev/ttyS0 /dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4 Baud_base: 115200, close_delay: 50, divisor: 0 closing_wait: 3000 Flags: spd_normal skip_test Terminalsoftware: sudo apt-get install minicom minicom -s # (start setup, because default is /dev/modem, which is not normally found)

If file exists...

Shell * [ parameter FILE ] OR test parameter FILE Where parameter can be any one of the following: -e: Returns true value if file exists -f: Return true value if file exists and regular file -r: Return true value if file exists and is readable -w: Return true value if file exists and is writable -x: Return true value if file exists and is executable -d: Return true value if exists and is a directory [ -e /dev/dvb/adapter0/ca0 ] && rm /dev/dvb/adapter0/ca0 [ -f /etc/rc.local ] && echo "rc.local found" || echo "rc.local not found"

Printing - CUPS - PPD - LPR

Printing Lenny Add: sudo lpadmin -p koeprinter -D "infoa tulostimesta" -E -v lpd://192.168.0.2/lp -P Brother_HL-1440.ppd Print: lpr -P koeprinter koe.txt Print raw (plt): lpr -P koeprinter -l koe.txt Remove: sudo lpadmin -x koeprinter Show options (if PPD-file added): lpoptions -p koeprinter -l Set options: lpoptions -p koeprinter -o PageSize=A4 Default LPD-port: 515 PPD-files: /etc/cups/ppd/ Configfile: /etc/cups/printers.conf and /etc/printcap D-Link lpd-queue: lp HP lpd-queue: raw1

Multiple IP:s, one network interface

Network Ubuntu 10.10 /etc/network/interfaces auto eth0 iface eth0 inet dhcp auto eth0:0 iface eth0:0 inet static address 192.168.2.10 netmask 255.255.255.0

One MAC-address, dhcpd3

Network Xubuntu 10.10 /etc/dhcp3/dhcpd.conf class "PS3" { match hardware; } subclass "PS3" 1:00:1F:A7:AB:5B:FD; ddns-update-style none; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 192.168.2.0 netmask 255.255.255.0 { option domain-name "example.org"; option domain-name-servers 8.8.8.8, 8.8.4.4; pool { range 192.168.2.128 192.168.2.250; allow members of "PS3"; } next-server 192.168.2.1; filename "kboot.conf"; option routers 192.168.2.1; }

Network Block Device - NBD

Linux Gentoo-PS3 -> Ubuntu 10.10 emerge python emerge nbd /etc/rc.conf nbd-server 1043 /dev/sr0 sudo apt-get install nbd-client sudo modprobe nbd sudo nbd-client 192.168.2.129 1043 /dev/nbd0 sudo mount /dev/nbd0 /cdrom

Booting from network

Network Debian 5 (Lenny) sudo apt-get install tftpd-hpa sudo apt-get install dhcp3-server sudo apt-get install nfs-kernel-server /etc/default/tftpd-hpa -> RUN_DAEMON="yes" (verbose: -vvvvvv) /etc/dhcp3/dhcpd.conf ddns-update-style none; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 192.168.2.0 netmask 255.255.255.0 { option domain-name "example.org"; option domain-name-servers 192.168.2.50; pool { range 192.168.2.128 192.168.2.250; } next-server 192.168.2.50; filename "pxelinux.0"; option routers 192.168.2.50; } cd /var/lib/tftpboot wget http://http.us.debian.org/debian/dists/lenny/main/installer-i386/current/images/netboot/netboot.tar.gz sudo tar xvfz netboot.tar.gz

Alsa to file

Sound Debian 6 (Squeeze) ~/.asoundrc #pcm. !default filewrite pcm.filewrite { type file slave { pcm "hw:Dummy" } file "| cat > /tmp/out_%r_%c_%b_%f_`date +%%s`.raw" perm 0777 format "raw" } Test: mpg123 -v -v -a filewrite -o alsa -r 48000 http://relay1.slayradio.org:8000 aplay /tmp/out_44100_2_16_S16_LE_1298980235.raw -r 44100 -f S16_LE -c 2

Handling Debian packages: apt-get/apt-file/dpkg

Debian Debian 6 (Squeeze) See what files package installs apt-file show PACKAGE Search file from packages apt-file search FILE See what files installed package includes dpkg -L INSTALLED_PACKAGE List installed packages dpkg --get-selections Install .deb-file dpkg -i DEBFILE Force remove dep dpkg --remove --force-remove-reinstreq DEBFILE Unpack .deb-file ar vx DEBFILE tar xvfz data.tar.gz tar tvfz data.tar.gz (just view without decompress) tar xvfz FILE data.tar.gz (extract single file) tar --xz -xvf data.tar.xz (XZ compressed data) Remove all but one: ls *|grep -v FILENAME|xargs rm -rf

Delete all but following files

Shell Debian 6 (Squeeze) ls | grep -v FILENAME1 | grep -v FILENAME2 | xargs rm -Rf

Compress and decompress initrd

Boot Debian 6 (Squeeze) Decompress initrd: mkdir /tmp/initrd cd /tmp/initrd zcat initrd.img | cpio -i Prepare and compress initrd: pushd . cd /tmp/initrd/lib/modules/2.6.37-1-686 sudo depmod -b /tmp/initrd 2.6.37-1-686 cd /tmp/initrd find . | cpio -o -H newc | gzip > /tmp/initrd.img popd

Qemu

Emulation Debian 6 (Squeeze) qemu -kernel vmlinuz -initrd initrd.img -append "root=/dev/sda" -hda hdimage

Aptitude (apt-get) and compiling from sources

Debian Debian 5 (Lenny) sudo apt-get source PACKAGE cd /usr/local/src/PACKAGE dpkg-buildpackage -rfakeroot -b sudo dpkg -i ../PACKAGE.deb

Search opened and recently written files

Debian Debian 5 (Lenny) sudo find / -mmin -5 sudo lsof

ccache

Compiling Debian 5 (Lenny) ~/.bashrc export PATH=/usr/lib/ccache:$PATH

ncftp

Network Debian 5 (Lenny) ~/.bashrc EDITOR="/bin/nano" ; export EDITOR ncftp -u [username] [ftp://address] edit [filename]

Use samba without authentication

Network Debian 6 (Squeeze) /etc/samba/smb.conf [global] guest account = kurkku security = share guest ok = yes follow symlinks = yes wide links = yes unix extensions = no

Debian - compiling kernel

Kernel Debian 5 (Lenny) apt-get install kernel-package ncurses-dev fakeroot wget bzip2 cd /usr/src wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.37.4.tar.bz2 tar xvfj linux-2.6.37.4.tar.bz2 cd linux-2.6.37.4 cp [old/debian-config-file] .config nano Makefile (extraversion) [export CONCURRENCY_LEVEL=3] (multiple threads/cores) make menuconfig make-kpkg clean fakeroot make-kpkg --revision=custom.1.0 kernel_image dpkg -i kernel-image-2.6.37.4_custom.1.0_i386.deb update-initramfs -k 2.6.37.4 -c

Show processtree

Kernel Debian 5 (Lenny) ps -ef --forest | less

Root password recovery

Authentication Debian 6 (Squeeze) Solution 1: Kernel parameter in bootloader: init=/bin/sh or single mount -n -o remount,rw / mount -avt nonfs,noproc,nosmbfs cd /etc vi passwd vi shadow Solution 2 (boot with emergency/bootdisk or other computer): mkdir recovery mount /dev/hda3 recovery cd recovery/etc vi shadow vi passwd To disable the root password, edit the second data field in the password file so that it is empty.

Turn monitor off

Energy saving Debian 6 (Squeeze) sudo apt-get install vbetool vbetool dpms off
To Do:
-shell: du, df
-initrd: blacklist
-kernel: compile/packing/install
-boot: grub, configure/update
-shell: sed, replace string
-shell: find|grep
-shell: lsof
-shell: sensors
-network: bwm-ng
-network: alpine, mutt (smtp)
-shell: ccache
-shell: make -j2
-network: samba, fstab, iocharset (ISO-8859-1, UTF)
-network: samba, mount, iocharset (ISO-8859-1, UTF)
-shell: characterset conversion
-find illegal characters from filenames
-network: iptables/ipforward, NAT
-network: apache, redirect
-network: apache, password authentication
-linux: apt, backport
-network: open ports
-shell: file, ldconfig, ldd
-kernel: depmod
-shell: output redirect, error redirect
-boot: udev
-shell: chown, chmod
-linux: raid1
-shell: reset