Linux/Unix usage tips

This is memo for myself (thus not necessarily self-explanatory for all) about various GNU/Linux and Unix related commands that I have used since around 1999. The tips are in chronological order, which means that the first ones are more likely deprecated than later ones.

To utilise this web-page in plain text format, e.g. with grep or emacs, you might want to remove/convert some HTML tags:
sed -e 's/&#60;/</g' -e 's/&#62;/>/g' -e '/^<pre>$/d' -e '/^<\/pre>$/d' linux.html > linux.txt

Seppo Heikkila, last updated: 2014-02-23

Basic file commands

Command [extra params] Description
man command Shows the manual-page for command.
info command Shows the info-page for command(more detailed than man).
cp [-R] from_where to_where Copy files from place to place.
mv from_where to_where Move files from place to place.
rm [-rf] target_file Remove files
du [-sk] disk usage in kilobytes
swapon [-s] swap usage (summary)
free displays free memory and swap resources
dmidecode Dump DMI (SMBIOS) table to human readable format
cardctl PCMCIA card control utility ( e.g. cardctl ident)
top displays the top CPU processes
ln [-s] real_dir_name link_name make hard or symbolic links to files
locate file_name search for files
mount /dev/device /mnt_place [-o uid=user,gid=group,umask=0007] Sets up(mounts) a file system to /mnt_place directory.
umount /dev/device Unmounts the wanted device.
dmesg print or control the kernel ring buffer.

Adding groups and users

Commands adduser and addgroup will deal with this. The settings are saved into /etc/group. For example group root0 where belong ssheikki and www-data is defined like this:
To show the groups where user_name belongs to:
groups user_name

Mounting devices

Mounts are loaded from /etc/fstab in the startup.
For example line(in /etc/fstab)
/dev/hda1 /c vfat gid=root0,uid=www-data,umask=0007 0 0
mounts the /dev/hda1 to /c with given parameters.

Same can be given also from command-line:
mount /dev/hda1 /c -o gid=root0,uid=www-data,umask=0007

To see all partitions, use:
fdisk -l command
If you want for example remount your read filesystem to rewritable, use;:
mount -o remount,rw /dev/hda2

Mouse Settings

Mouse device is /dev/mouse, a symbolic link(ln -s) to the physical device, such as:
/dev/ttyS0 for COM1
/dev/ttyS1 for COM2
/dev/ttyS2 for COM3
/dev/ttyS3 for COM4

Mouse can be configured using gpmconfig which is config for gpm. The settings for standard ps2 mouse are following:
Set the responsiveness (normally not needed) [1]?
> 10
Repeat protocol (enter 'none' to turn repeating off) [raw]?
Do you want to add any additional arguments []?
Do you want to test this configuration (y/N)? y
gpm -m /dev/psaux -t imps2 -r 10 -Rraw
Finish testing by typing Ctrl-D

Current configuration: -m /dev/psaux -t imps2 -r 10 -Rraw
Device: /dev/psaux
Type: imps2
Responsiveness: 10
Repeat_Type: raw

Runtime information /proc/

The /proc file system is a pseudo-filesystem that stores relevant informations about the kernel(man 5 proc). For example /proc/interrupts shows how many times each IRQ was used and by whom.

Unix has Different Run Levels

Each run level has own configuration files. In debian they are in /etc/rc#.d/ and in redhat they are /etc/rc.d/rc#.d/ (# means the run level number).

Power Off: Run Level 0(/etc/rc0.d/)
Single User: Run Level 1(/etc/rc1.d/)
Multiuser: Run Level 2(/etc/rc2.d/)
Full Multiuser(2 with NFS): Run Level 3(/etc/rc3.d/)
Unused: Run Level 4(/etc/rc4.d/)
X11(graphical): Run Level 5(/etc/rc5.d/)
Reboot: Run Level 6(/etc/rc6.d/)

To change boot behaviour, modify /etc/inittab. The run levels are also described there.

A script starting with S starts a service. One starting with K stops a service. The number after the `S' or `K' specifies the order in which the scripts are run. For example, S25xdm will start before S35xdm.

Stop/Start/Restart scripts

Subdirectory /etc/init.d/ (or in redhat /etc/rc.d/init.d) contains all startup scripts that may be used to stop/start/restart the related process. For example /ec/init.d/gpm stop will stop the mouse and /ec/init.d/gpm start will start it again.

Installing kernel

/usr/src/linux/README tells what to do. First download the latest source. Then everything starts with "make menuconfig". If you don't have ncurses-dev installed please find it from the web or in debian just use "apt-get install ncurses-dev".

As simplest, the following steps should be taken(with 2.4.x kernel):
make menuconfig
make dep
make bzImage
make modules
make modules_install
make install

or using with make-kpkg:
make-kpkg --targets
make-kpkg buildpackage

Things to remember in menuconfig

To select modules for different kernels in /etc/modules

Write following to /etc/modules:
if `kernelversion` == 2.4
elseif `kernelversion` == 2.6

Window managers

To handle logging I recommend; wdm(WINGs Display Manager).
For actual managers you should try;

Test if your port X is open

To resolve net-addresses

Use nmap, host and dig programs.


lspci, Shows info about your pci cards(replaces /proc/pci)
tune2fs, from ext2 -> ext3 for example.

[1] Linux Administration Guide

To setup a new disk

Partition the disk: cfdisk.
Make it ext3: mke2fs -j /dev/hdXX
Set parameters, turn ext2, etc: tune2fs -m 0 /dev/hda1
Remember to put DMA on: hdparm -c /dev/hdb, hdparm -c 1 /dev/hdb
Good configure for hdparm is for example:
 multcount    = 16 (on)
 I/O support  =  1 (32-bit)
 unmaskirq    =  1 (on)
 using_dma    =  1 (on)
 keepsettings =  0 (off)
 nowerr       =  0 (off)
 readonly     =  0 (off)
 readahead    =  8 (on)
 geometry     = 19457/255/63, sectors = 312581808, start = 0
 busstate     =  1 (on)
and acceptable speed for example:
ssheikki:~# hdparm -Tt /dev/hda

 Timing buffer-cache reads:   128 MB in  0.43 seconds =297.67 MB/sec
 Timing buffered disk reads:  64 MB in  1.17 seconds = 54.70 MB/sec
If you get "HDIO_SET_DMA failed: Invalid argument", when setting hdparm -d1 /dev/hda then your kernel is missing VIA module. Select it from:
ATA/IDE/MFM/RLL support  --->  
  IDE, ATA and ATAPI Block devices  --->
    <*>     VIA82CXXX chipset support 
For real world tests:
Writing speed:
time dd if=/dev/zero of=test bs=1048576 count=1024
Reading speed:
time dd if=test of=/dev/null bs=1048576 count=1024

In the end you can umount your file system and do fsck(filesystem check):
For ext2 in is done: e2fsck -c -c -C 0 -f -v /dev/hdXX

Helvetin skandit

You can try these and hope that it will work! :)
1. loadkeys fi-latin1
2. add to /etc/locale.gen following
fi_FI ISO-8859-1
fi_FI@euro ISO-8859-15
And the run locale-gen.
4. xorg.conf keyboard should look about like this for Finns:
Section "InputDevice"
        Identifier  "Keyboard0"
        Driver      "keyboard"
        Option      "XkbRules" "xorg"
        Option      "XkbModel" "pc105"           # pc105 is finnish
        Option      "XkbLayout" "fi"

/dev/null breaks

rm the old and create new with:
mknod -m 666 /dev/null c 1 3
The break might cause for example sshd fail to start(sshd[756]: fatal: daemon() failed: Success).

Change finger information

Use chfn command.

Setting up libraries

Add library paths in:
See man for the following commands:
ldd program

Gphoto2 & USB settings

You need USB support from kernel(see preferred kernel settings below and/or Linux USB).
You need: libusb
You need: libgphoto2 installed. Remember to see that usb is found by libgphoto2.
Last you need: gphoto2 installed.
How to know that something might work:
less /proc/bus/usb/devices
gphoto2 --list-ports
gphoto2 --auto-detect

Prefered kernel settings for usb:
debian:/usr/src/kernel/linux-2.6.7# grep -i usb .config | grep -v "#"

Find out who is using some file or socket

fuser -v /resource

Ssh authentication without password

Goto computer FROM where you want to access some computer:
Generate key pares:
ssh-keygen -b 2048 -t dsa
Copy the file to the computer you want to access. If many computers, just append the to authorized_keys-file.
scp user@remotehost:.ssh/authorized_keys
And volaa... do a test:
ssh user@remotehost

Install windows and Linux on different harddrives, Lilo config

Situation example: linux on Master Disk MBR(/dev/hda) and windows on Slave Disk MBR(/dev/hdb). In this situation, linux bootloader(lilo in this example) starts from Master MBR. To add Windows boot you need to add following choice to /etc/lilo.conf.
It changes the active disk in the boot so Windows will be booted unnoticed.

Where are your cd-roms

To see this, cat:
cat /proc/sys/dev/cdrom/info

Second LoopBack interface/ip for local usage

If you want, for example, to point to your own computer, use:
/sbin/ifconfig lo:1

Test in local:
ssheikki@jt11-231-2:/$ traceroute
traceroute to (, 30 hops max, 38 byte packets
 1  jt11-231-2 (  0.061 ms  0.020 ms  0.014 ms
Test in computer where loopBack adapter isn't used:
ssheikki@jt7-236:~$ traceroute
traceroute to (, 30 hops max, 38 byte packets
 1  trinet-gw (  2.303 ms  2.331 ms  3.403 ms
 2 (  0.899 ms  0.634 ms  0.681 ms
 3 (  0.833 ms  4.314 ms  0.591 ms

Howto setup http over SSL(https)

creating the certificate and config apache
securing the actual webpages

Howto tunnel RMI through HTTP

  • Install Apache 2.x to port 80.
  • Install Tomcat 4.x to port 8080. For windows, use exe-installer.
  • Install Tomcat Web Server Connectors, i.e. get mod_jk_1.2.x.dll(in linux
  • Make sure you have following lines in Apache httpd.conf:
    LoadModule proxy_module modules/
    LoadModule proxy_connect_module modules/
    LoadModule proxy_http_module modules/
    LoadModule rewrite_module modules/
    Options Indexes FollowSymLinks ExecCGI
        AllowOverride None
        Options +ExecCGI
        Order allow,deny
        Allow from all
    RewriteEngine on
    RewriteLog C:/tomcat/rewrite.log
    RewriteLogLevel 9
    RewriteRule ^/cgi-bin/java\-rmi\.cgi$ http://localhost/examples/servlet/ServletHandler    [P]
    LoadModule jk_module C:/Winnt/system32/mod_jk_1.2.5_2.0.47.dll
    JkWorkersFile "C:/tomcat/conf/"
    JkLogFile "C:/tomcat/logs/mod_jk.log" 
    JkLogLevel info 
    JkMount /manager ajp13
    JkMount /manager/* ajp13 
    JkMount /examples ajp13
    JkMount /examples/* ajp13 
    JkMount /tomcat-docs ajp13
    JkMount /tomcat-docs/* ajp13 
    JkMount /webdav ajp13
    JkMount /webdav/* ajp13 
    JkMount /*.jsp ajp13 
  • tomcat/conf/ should contain:
    worker.list=ajp13, ajp14
  • Tadaa... you might want to test with:
  • My iteration time for this easy setup was 16h. :I

    Image and video screen capture in Linux

    The software for this is xvidcap.
    To capture in avi format for example:
    xvidcap --file grap.avi --time 100
    Brilliant! :)

    Making thumbnails images

    Use convert:
    convert -resize 15x15% original.gif original_thumb.gif

    It might be usefull to use script:
     for image in *.jpg
       echo "Processing: $image ..."
       convert  -resize 15x15% $image thumbs/$image
       echo "done."

    Create animated gifs

    Gifmerge is neat and simple:
    ./gifmerge -l0 -10 animate_this/*.gif > anim.gif

    Sometimes you might to need a script, that selects non-duplicate images and converts them to be in right format and then creates the animation:
    mkdir __tmp
    for image in *.gif
      if [ $image_prev ] ; then
         diffout="`diff $image_prev $image | wc -l`"
         if [ $diffout = "0" ] ; then
            echo "Identical images: $image_prev $image, not processed."
            convert  -resize 100x100% $image __tmp/$image
            echo "Image $image processed."
        convert  -resize 100x100% $image __tmp/$image
        echo "Image $image processed."
    ./gifmerge -l0 -10 __tmp/*.gif > anim.gif
    rm -rf __tmp
    echo "Output should be here:"
    ls -laF anim.gif
    echo "done."

    Shell scripting

    DVD players

    Install ogle and ogle-gui. Remeber that you also need libdvdcss for all movies to be readable.

    Example run:
    ogle -u gui /dev/hdc

    Howto install foreign packages(rpm, etc.) in debian

    There is program called alien, which converts packages to debian packages which can be then easily installed:
    alien - Convert or install an alien binary package

    alien --to-deb cool-program.rpm
    dpkg -i cool-program.deb

    Howto merge and edit avi-files

    Install avidemux or avimerge.
    Note: Avimerge is easier but has problems with audio and etc.

    Video editors

    avidemux - best with avi files, at least, maybe best in others too.

    Clock synchronization with NTP

    Network Time Protocol debian packages: ntp, ntp-simple.
    List ntp servers:
    ntpq -p

    Howto capture stream data:

    - to capture rm-stream into wav:
    vsound -t -v -f output.wav RealPlayer8/realplay input.rm
    vsound: digitally record output of an OSS audio program.

    - rip radio streams to mp3 files:
    streamripper URL

    Howto convert sound into mp3/ogg

    - audacity - Graphical cross-platform audio editor.
    Encodes wav to mp3/ogg and lots of more. And use through very usable GUI! Brilliant! Myös Suomen kielen tuki löytyy!

    Timing commands

  • at: input time and wanted commands to execute.
  • crontab input.file: crontab -l list the commands to be executed.

    Where the executed program is on the path and it's man page


    Example, where is whereis program:
    root@debian:/# whereis whereis
    whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz

    Search files recursively for wanted string, windows and linux

    grep -r search_string *

    Windows(not in XP):
    search search_string

    Wget and for example

    for((i=9201;9300>i;i++)); do wget$i.jpg ;done

    Converting video formats, e.g. vro to avi/mpeg/etc

    Use memcoder, which is part of the mplayer:
    mencoder source.vro -o output.avi -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1800 -oac copy
    Notes: -ovc defines video codec.
    Notes 2: msmpeg4 codec works in Windows

    Converting mov -> avi

    mencoder *.MOV -o koeX.avi -srate 8000 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1800 -oac mp3lame -lameopts vbr=3:br=32

    Update alternative packet

    update-alternatives --config automake

    Display network information

    netstat -a
    Print network connections, routing tables, interface
    statistics, masquerade connections, and multicast memberships.

    Executing X programs as root

    Install sux. Log in as normal user who is allowed to use X programs. Write sux -, behaves just like su but transfers $DISPLAY and the X cookies.

    Securing computer for local-hack

    Disable floppy boot and add-password for lilo: security + howto.

    More sequrity issues: ulimit.

    Bluetooth installation

    Pretty good tutorial is here.

    But basically it's like this:

    Execute images with qemu

    The QEMU System emulator simulates a complete PC!

    Update dynamic libraries

    Configure dynamic linker run-time bindings:

    Security tools

    Nessus; free, powerful, up-to-date and easy to use remote security scanner.
    tiger; report system security vulnerabilities.

    Neural Network implementations

    Fast Artificial Neural Network Library implements multilayer artificial neural networks in C with support for both fully connected and sparsely connected networks:

    USB hard disk

    - Check that disk is detected, e.g.: less /proc/bus/usb/devices
    - Partition the disk, e.g.: cfdisk /dev/sda
    - Format the partitions, e.g.: mke2fs -j /dev/sdaX
    - Test speed(~27MB/sec) e.g.: hdparm -tT /dev/sda6
    - Mount and enjoy, e.g.: mount -t ext3 /dev/sda6 /usbhd


    smbstatus, smbclient, smbmount.


    set up: cvs -d CVSROOT init
    import: cvs -dCVSROOT import projektinnimi vendor_tag release_tag
    e.g. cvs -d/private/cvs_repository import peacebot TKK start
    set CVSROOT: export

    Benchmarking computers

    LMbench, Tools for Performance Analysis.

    Open connections

    Show all open connections: netstat -a
    Show port numbers: netstat -n -a
    Who is using port: fuser -n tcp
    Verbose who is using port: fuser -n tcp -v

    DNS name server

    apt-get install bind
    To create for exaple alias for
    master zone
    and the name alias jt11-117-3
    For easy configuration, please install webmin.
    webmin-bind, webmin-apache, webmin-samba, etc...
    Note that webmin starts it's own http server:

    Analyze X-window connections

    xdpyinfo - display information utility for X
    xev - print contents of X events
    xwininfo - window information utility for X

    Partitioning disk in linux so that windows understands it

    Partion like this,
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        1824    14651248+   c  W95 FAT32 (LBA)
    /dev/sdb2            4256       30401   210017745    5  Extended
    /dev/sdb3            1825        4255    19527007+   c  W95 FAT32 (LBA)
    /dev/sdb5   *        4256        5471     9767488+  83  Linux
    /dev/sdb6            5472       30401   200250193+  83  Linux
    Now evetyhing is ok but the Extended type is wrong. Let's change it with fdisk.
    Command (m for help): t
    Partition number (1-6): 2
    Hex code (type L to list codes): L
    Hex code (type L to list codes): f
    Command (m for help): w
    Now the table looks like this:
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        1824    14651248+   c  W95 FAT32 (LBA)
    /dev/sdb2            4256       30401   210017745    f  W95 Ext'd (LBA)
    /dev/sdb3            1825        4255    19527007+   c  W95 FAT32 (LBA)
    /dev/sdb5   *        4256        5471     9767488+  83  Linux
    /dev/sdb6            5472       30401   200250193+  83  Linux

    Backup whole mysql-database

    Dump all databases with root access:
    mysqldump --all-databases -p -u root | gzip -c > mysql_dump_archive.sql.gz

    To restore the databases, run the console output of gzip through mysql:
    gzip -cd mysql_dump_archive.sql.gz | mysql -u root -p

    Another option is to log as a root into a mysql database:
    mysql -u root -p
    If you do not remember your password, you can reset it using root shell:
    /usr/bin/mysqladmin -u root password 'new_password'
    and then execute
    source mysql_dump_archive.sql;

    Upgrading mysql database from 1.5 to 1.7.1 (Ubuntu)

    Step1: Take backup of the mysql database and save AdminSettings.php and LocalSettings.php files. Install using aptitude the new mediawiki version (do not configure it!!, just install, i.e. aptitude install mediawiki). Copy AdminSettings.php and LocalSettings.php to /var/lib/mediawiki1.7 directory.

    Step2: Sign in the mysql database (mysql -u root -p) and rename your old table to text table. Like this:
    usedb wikidb;
    rename table sm_old to sm_text;

    Step3: Go to the /usr/share/mediawiki1.7/maintenance directory and command "php upgrade.php". All should go happily and last print is "Done.". Then command "php refreshLinks.php" to finish. Now the database should work again as before (or better).

    Backuping the mediawiki

    Make a static html page backup with:
    php /usr/share/mediawiki1.7/maintenance/dumpHTML.php -d /destination/dir
    Make an xml dump of the database:
    php dumpBackup.php --full > dumpBackup.xml
    Dump mysql databases:
    mysqldump --all-databases -p -u root | gzip -c > mysql_dump_archive.sql.gz

    GANTT chart - project management tool



    /set term_charset ISO-8859-15
    /set term_force_colors ON

    sftp/scp connection with chroot

    You can restrict the user to his home directory:
    apt-get install scponly
    Check that /usr/sbin/scponlyc has suid:
    chmod 4755 scponlyc

    Using rdesktop

    Opening a connection with 24bit 80% windows size and with local disk linked to the remote computer:
    rdesktop -a 24 -g 80% -r disk:yebbey=/home/ssheikki/

    Opening a connection with 24bit fullscreen and with local disk linked to the remote computer:
    rdesktop -a 24 -f -r disk:yebbey=/home/ssheikki/

    Connecting a computer behind firewall:
    If you have a ssh server that you can connect at TKK, just make a ssh tunnel to that computer like this:
    ssh -L username@autlab
    Now you can open remote desktop just by connecting:
    rdesktop -a 24 -f -r disk:localdisk=/home/username/ localhost:7777

    SVN (Subversion) howto

    svn checkout

    Status of local files compared to the svn repository:
    svn status [files/dirs]

    svn commit [files/dirs]

    svn commit [files/dirs]

    Resolve (my files are good, update them to repository):
    svn resolved [files/dirs]

    Revert (my files are crap, get original ones from repository):
    svn revert [files/dirs]

    Check what is the status of files in current directory:
    svn -v status


    subversion howto with https

    List project in repository:
    svn --username ssheikki list https://localhost/svn/

    Import a directory (svnhowto) to repository as svnhowto:
    svn --username ssheikki import svnhowto https://localhost/svn/svnhowto -m "initial import"

    Checkout all from repository :
    svn --username ssheikki checkout https://localhost/svn

    svn commit

    svn delete svnhowto

    subversion howto with ssh

    Same commands as above but you need to give path in the server:
    export SVN_SSH="ssh -l ssheikki"
    svn checkout svn+ssh://aut40/svn_repository/project_name

    subversion howto with local repository

    svn co file:///svn_repository/project_name

    Multiple ssh connections via one ip

    Add in /etc/ssh/ssh_config or in ~/.ssh/config
    Host aut40
            Hostname        yourserver.ftl
            Port            49490
            HostKeyAlias    aut40
            CheckHostIP no
    Host lap
            Hostname        yourserver.ftl
            Port            49491
            HostKeyAlias    lap
            CheckHostIP no

    Pasword change with first visit

    After creating the username, set the password to be expired. It requires user the change it when he tries to log in:
    passwd -e

    Howto backup your hard disk

    dump and restore packages

    Tar exclude directory

    tar -cvfX tar-name.tar exclude-file dirtobetarred/

    Find file with full path and date

    find . | grep McCtrl.c > /tmp/lsgreptmp && ll `cat /tmp/lsgreptmp`

    Kernel magic instructions

    List instructions, helps if computer is jammed:
    Alt + Prnt Screen + h

    Display all IRQ:s

    cat /proc/interrupts

    Design programs (open source)

    * Inkscape (, Open Source vector graphics editor, with capabilities similar to Illustrator, Freehand, CorelDraw, or Xara X.
    * Dia (, diagram creation program, inspired by the commercial Windows program 'Visio'.
    * GIMP (, GNU Image Manipulation Program, for such tasks as photo retouching, image composition and image authoring.

    Programming editors (open source)

    # Code::blocks ( (Windows)
    # devcpp ( (Windows)

    Tell command that parameters end

    Problem, e.g. howto remove --bzip2 file. Answer:
    rm -- "--bzip2"


    xdvi - display dvi files
    Create a one big html page from the tex document:
    latex2html -split 0 thesis.tex

    Mplayer and DVD subtitles

    mplayer -sid ID DVDFILE.VIDEO

    Create ssh-tunnel

    Tunnel FROM port 10024 TO localhost port 22:
    ssh -N -R 10024:localhost:22 -2

    Ssh forward in case GatewayPorts off

    Computer behind firewall:
    ssh -v -N -R 49490:localhost:22 -2
    Computer being forwarder:
    mkfifo in out
    cat out | nc -l -p49491 > in
    cat in | nc localhost 49490 > out

    Dave port:
    ssh -N -L 81:localhost:81 -2


    Create a CVS repository where your projects are saved:
    cvs -d /absolut/path/of/your/repository init

    Put your project to the CVS repository:
    cd /directory/where/your/projects/is
    cvs -d /absolut/path/of/your/repository import -m "Name of your Project" modulename_of_your_project vendor_name version_1_0_0

    Get the stuff from CVS:
    cd /new/working/directory/of/you/project
    cvs -d /absolut/path/of/your/repository co modulename_of_your_project

    Update, add and Commit cvs:
    cvs -d /absolut/path/of/your/repository update
    cvs -d /absolut/path/of/your/repository add name_of_file_tobe_added
    cvs -d /absolut/path/of/your/repository commit

    WLAN howto

    Enable internal driver, e.g. for Acer Aspire 5021WLMi:
    1) Download and install acer_acpi:
    make acer_acpi.ko # How to compile the driver for 2.6 kernel
    modprobe acer_acpi
    echo "enabled: 1" >/proc/acpi/acer/wireless
    Install wlan driver, e.g. for Broadcom BCM5700:
    modprobe ndiswrapper
    ndiswrapper -i bcmwl5.inf

    Scan for network interfaces:
    iwlist wlan0 scan
    Connect wlan0 into a network node if found:
    iwconfig wlan0 essid ESSID_OF_FOUND_NETWORK
    ifconfig wlan0 up
    Get connection settings:
    dhclient wlan0

    PPPOE howto

    First time

    Make sure PPP is enabled in the kernel!
    Configure pppoe:

    After first time

    Make sure that server is started:
    /etc/init.d/ppp start
    Start pppoe connection:
    pon dsl-provider

    Continue http-download

    wget -c

    Download one page with all it is inline contents, e.g. images

    Download all photos on the page:
    wget -H -p -nd -Ajpg

    Emulate 32bit, chroot

    chroot /var/chroot/sid-ia32

    Sending attachment files in linux

    mutt -s "Test" -a Attachment.tar.bz2 < body_message.txt

    Compiling kernel in Debian with make-kpkg

    Configure kernel:
    make menuconfig
    Compile kernel into debian package:
    make-kpkg buildpackage
    If this fails for some reason, you might want to do a clean:
    make-kpkg clean

    Compiling kernel-modules in Debian with make-kpkg

    Copy kernel-module codes into location defined by MODULE_LOC (default is /usr/src/modules). Build modules:
    make-kpkg modules

    Open remote desktop connection

    rdesktop -k fi -d universe -u seppo.heikkila

    Partition a USB stick with messed partition table

    Create new partition and ignore the one used:
    cfdisk -z /dev/sdb

    Format file system for windows (mkfs.vfat is part of dosfstools package)
    mkfs.vfat /dev/sdb1

    Howto install/update debian packages offline

    Update your package list apt-get --print-uris update | sed s/\'//g
    Download the packes e.g. with wget or apt-zip script. Use bunzip2 or gunzip to extract all source and packages files.
    rename 's/Sources$/Sources.bz2/' *Sources && bunzip2 *.bz2
    rename 's/Packages$/Packages.bz2/' *Packages && bunzip2 *.bz2
    Copy the downloaded files to /var/lib/apt/lists/ and update the package list by running
    apt-get check

    Get packages apt-move and apt-zip:
    apt-get --print-uris install apt-zip
    apt-get --print-uris install apt-move
    and copy them to /var/cache/apt/archives/. Then you can just use apt-get install to install the packages.

    Generate a package download script
    apt-zip-list -m /usbstick -a upgrade
    To do the same in random directory, use the --skip-mount parameter. In UNIX/Linux, run the script to get packages. If you have to use a windows machine, see below.
    Download in windows
    Download unix tools package, e.g. UnxUtils.

    In case proxy servers have to be used, set http_proxy and ftp_proxy.
    export http_proxy=
    export ftp_proxy=

    Modify the script to work in windows:
    - separate parameters
    p1 = `echo $1 | gawk '{print $1}'`
    p2 = `echo $1 | gawk '{print $2}'`
    - add wget proxy username and password
    wget --proxy-user=USERNAME --proxy-passwd=PASSWD -t3 -nv -O $2 $1
    Install downloaded packages apt-zip-inst does not seem to work so you can copy the packages directly to /var/cache/apt/archives/. Then just install the packages by running
    apt-get upgrade
    Install new individual packages Get urls of your_package update urls:
    apt-get -y --print-uris install your_package | grep deb | cut -f1 "-d " | sed s/\'//g
    Download your package, copy it to /var/cache/apt/archives/ and install it normally using apt-get install
    apt-get install your_package

    Autofs removable devices

    Get autofs packet:
    apt-get install autofs

    Create a /etc/auto.master file with this content
    /var/autofs/removable /etc/auto.removable --timeout=2
    The timeout defines when you can pull the device out.

    Create auto.removable file
    usbstick        -fstype=vfat,rw,gid=100,umask=002       :/dev/sda1
    cdrom           -fstype=iso9660,ro,sync,nodev,nosuid    :/dev/hdc
    Create symbol links to this paths
    ln -s /var/autofs/removable/usbstick /usbstick
    ln -s /var/autofs/removable/cdrom /cdrom

    Restart autofs:

    Use the device, e.g.
    ln -laF /usbstick
    You can pull the device out after "timeout" seconds has passed.

    Connect to vnc server

    For example realvnc compatible is
    vncviewer address:display

    Add apt-get pgp-key

    After getting verification error while apt-get update, take the last 8 digits of the key and
    gpg --keyserver --recv-keys 2D230C5F
    gpg --armor --export 2D230C5F | apt-key add -

    Who or what is using file

    fuser used_file_or_device

    Transfer file using serial cable

    Send file:
    cat file > /dev/ttyS0
    Read file:
    cat /dev/ttyS0

    How can you see contents of debian package

    dpkg --contents package.deb

    Howto encrypt yout harddisk

    Make sure that you have these modules in your kernel:
    dm_mod, dm_crypt, sha512, aes

    Format a device as luksDevice which is standard for hard disk encryption (Linux Unified Key Setup). Enter password when asked:
    cryptsetup -c aes-cbc-essiv:sha256 luksFormat /dev/sda1

    Create mapping to the drive:
    cryptsetup luksOpen /dev/sda1 sda1

    Now you can access your device in address /dev/mapper/sda1. You can e.g. format it with mkfs.ext2 and mount it.

    Encrypt with truecrypt

    Good encryption algorithms:
    Hash algorithm: Whirlpool
    Encryption algorithm: AES

    Create a ext2 partition on the disk:
    truecrypt -v -c /dev/sda1
    truecrypt -N 1 /dev/sda1
    mkfs.ext2 /dev/mapper/truecrypt1
    mkfs.ext2 mkfs.ext2 -m0 -T largefile4 /dev/mapper/truecrypt1 # for large files, inode size 4MB instead of 8kB
    tune2fs -l /dev/mapper/truecrypt1 # Check what was done, e.g. inode size on 128B

    To mount into directory mnt
    truecrypt /dev/sda1 mnt
    To unmount directory mnt
    truecrypt -d sda1

    Change keyboard variant

    Change X-keyboard layout
    Change X settings on the fly
    setxkbmap -layout fi -variant nodeadkeys

    Download files from link page

    wget -O - | wget -i -

    Encode CD to ogg/mp3

    Install mp3c package and rip+encode with the menu interface. Could not be easier!

    Webcam Logitech for Notebooks Pro (ID 046d:08cb), 2006/2007 model

    Kernel module:


    Webcam Logitech Quickam Connect (ID 046d:08d9)

    Kernel module:

    gqcam -v /dev/video1
    xawtv -geometry 640x480

    Subversion on localhost or over ssh

    Create the subversion repository to localhost:
    svnadmin create /var/svn/my_project

    On localhost start the subversion daemon:
    svnserve -d

    Checkout the project:
    svn co svn://localhost/var/svn/my_project

    In order to be able to add and commit stuff, you have to edit the /var/svn/my_project/conf/svnserve.conf and maybe add "anon-access = write" or create password database.

    To use the project in remote computer, run:
    svn co svn+ssh://server_address/var/svn/my_project
    To connect to a server with different port than 22, e.g. this in .ssh/config helps:
    Host lap
            Port            49491
            HostKeyAlias    lap
            CheckHostIP no

    Update sources.list packages

    Deciding which mirror is the best to include in the sources.list file:
    netselect, netselect-apt
    Debian worldwide mirror sites:
    Generate fastest sources.list selection for sid:
    netselect-apt sid

    Howto find out which package a given file belongs to

    dpkg -S stdio.h
    apt-file search filename
    To see all the files that package contains:
    apt-file list packagename

    List installed packages

    COLUMNS=132 dpkg -l

    Install packages on demand

    auto-apt run ./configure

    Compile deb package sources

    Get package:
    apt-get source packagename
    Compile package:
    apt-get -b source packagename
    Install then package:
    dpkg -i file.deb

    Reference tutorial: [1].

    Find out what traffic is hammering your computer

    See ports and bytes with
    Iptraf e.g. in the open WLAN network shows all the traffic so it might be necessary to add filters e.g. to show only traffic to/from your computer. Watch the detailed traffic with

    Is your DNS lookup not working

    It is configured in:
    You might need to fix that for chroot:ed versions especially.

    Firefox to work in chroot

    First install some sound packages and flash:
    apt-get install alsa-base alsa-oss alsa-utils flashplugin-nonfree
    Then make sure that your /etc/iceweasel/iceweaselrc file has either line ICEWEASEL_DSP="auto" or ICEWEASEL_DSP="aoss". Then it should work.

    Configure firefox options

    Write about:config to the address bar and be happy.

    Firefox save as... not working

    Try to delete this file from your local firefox settings.

    Lossless jpeg manipulation

    apt-get install libjpeg-progs
    For example rotation:
    jpegtran -rot 90 -trim foo.jpg > foo90.jpg

    Compare directories

    To see what files differ in the given directories, command:
    diff -r --brief dir1 dir2

    Take screenshot of the desktop

    After installing ImageMagick:
    import screenshot.jpg

    Check last logins to the system

    As a root:

    Controlling X-server connection rights

    xhost - server access control program for X
    Grant rights to all hosts:
    xhost +

    Howto configure network to work manually

    You need to know IP, MASK, GATEWAY, DNS, HOSTNAME and DOMAIN:
    ifconfig eth0 IP netmask MASK up
    route add -net default gw GATEWAY netmask eth0
    hostname HOSTNAME
    echo ``domain DOMAIN'' >/etc/resolv.conf
    echo "nameserver DNS" >>/etc/resolv.conf

    Tools to check ethernet speed

    mii-tool, ethtool, iperf
    :~# mii-tool -v eth0
    eth0: negotiated 100baseTx-FD flow-control, link ok
      product info: vendor 00:07:32, model 17 rev 3
      basic mode:   autonegotiation enabled
      basic status: autonegotiation complete, link ok
      capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
      advertising:  100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
      link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
    :~# ethtool eth0
    Settings for eth0:
            Supported ports: [ TP ]
            Supported link modes:   10baseT/Half 10baseT/Full 
                                    100baseT/Half 100baseT/Full 
            Supports auto-negotiation: Yes
            Advertised link modes:  10baseT/Half 10baseT/Full 
                                    100baseT/Half 100baseT/Full 
            Advertised auto-negotiation: Yes
            Speed: 100Mb/s
            Duplex: Full
            Port: Twisted Pair
            PHYAD: 0
            Transceiver: internal
            Auto-negotiation: on
            Supports Wake-on: pumbg
            Wake-on: g
            Current message level: 0x00000033 (51)
            Link detected: yes
    ipref measures the traffic between two comptures. Other computer is server and the other computer is client.

    To find out what libraries program needs

    Check by running:
    ldd programname
    To add a new dynamic library:
    ldconfig -n /path/of/new/lib
    For more info, man

    Which user I am and which groups do I belong

    Use this command:

    Creating a CD

    To put on an audio CD all the *.wav files which are in the current directory:
    cdrecord dev=x,y,z -pad speed=0 -audio *.wav

    mkisofs -o cd.iso -J -R /tmp/mycd
    cdrecord -scanbus
    cdrecord dev=x,y,z -multi speed=0 -data cd.iso

    CD to wav

    Whole CD:
    cdparanoia -B
    Just one track:
    cdparanoia -w track_number file.wav

    wav to mp3 or ogg

    lame file.wav file.mp3
    oggenc file.wav -o file.ogg

    Split a file to several floppies

    split -b1m file
    cat x* >file

    Converting text files from DOS, Windows, Mac...

    Adopted from:
    Texts files under unix, mac, dos and windows use differents codes for end-of-lines and accentuated characters. Linux typically uses the Latin-1 character encoding. The ``recode'' program converts from one format to the other (info recode).
    To convert file.txt coming
    from a Macintosh: recode mac..latin1 file.txt
    To convert from DOS codepage 850 to unix latin1:
    recode 850..latin1 file.txt
    To just remove ^ M:
    recode l1/crlf..l1 file.txt
    To convert from Windows codepage 1250 to unix latin 1 (iso-8859-1): 
    recode ms-ee..l1 file.txt


    To put the '' into the printing queue of the printer known as 'printername':
    lpr -P printername

    The printers can be attached to the local system via a parallel, serial, or USB port, or available over the network. To get a list of available printers:
    lpstat -p -d

    To check the status of all printers:

    lpstat -a

    To remove a printing job:
    lprm job-id

    Vector graphics

    Maybe use 'xfig' to construct complex graphics. Yet the
    ergonomy of xfig is very different from what users expect nowadays.
    You can try 'sketch', 'dia' or OpenOffice draw. Or inkscape.
    For mathematical plots, bar plots..., I use the data analysis package
    R. For simple things, gnuplot may also help.

    Scan for badblocks

    This is destructive, so do it only for empty partitions:
    badblocks -v -w -p 3 -o /root/badblocks.list.txt /dev/sda1

    md5 check file for files in directory

    To create md5 check file, execute:
    find . -type f 2>/dev/null -exec md5sum {} \; >test.md5
    Check the directory:
    md5sum -c ../picsall.test.md5

    Need a secure kernel

    Ping HW address

    Usage example:
    ~# arping 00:0D:F0:14:B8:22
    ARPING 00:0D:F0:14:B8:22
    60 bytes from (00:0d:f0:14:b8:22): icmp_seq=0 time=434.160 usec
    60 bytes from (00:0d:f0:14:b8:22): icmp_seq=1 time=425.100 usec

    WLAN WEP in Linux

    iwconfig wlan0 essid myHost
    iwconfig wlan0 key s:passphrase
    iwconfig wlan0 up
    dhclient wlan0

    And all should work.

    WLAN WPA in linux

    WPA is more secure than WEP and should be prefered.
    Install wpasupplicant package:
    wpasupplicant - Client support for WPA and WPA2 (IEEE 802.11i)

    Manual configuration:
    1) Generate passphrase:
    wpa_passphrase myHost myPassPhrase
    Insert it into /etc/wpa_supplicant/wpa_supplicant.conf. 2) Run these commands:
    iwconfig wlan0 essid YebbeY
    ifup wlan0
    wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
    3) Connection is established so get a IP address:
    dhclient wlan0

    Automatic configuration:
    1) Add these to /etc/network/interfaces
    auto wlan0
    iface wlan0 inet dhcp
    up wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf -Bw
    down killall wpa_supplic

    Which distribution are you running?

    lsb_release -a

    Logical volume management

    Check lvm.

    Check that all files are unique, no duplicates

    fdupes -r /dir

    Check WLAN signal strength or quality


    Update GRUB menu


    Open remote desktop connection

    rdesktop -f -a 24 -r disk:homedir=/home/ssheikki

    Remove default gw from eth0 to enable connection through wlan0

    List routes:
    route -n
    Delete route that you do not want to use:
    route del default gw

    Howto grip owner of other user screen

    Check what is your console:
    Change full rights to the console:
    chmod 777 /dev/pts/32
    Change to the user with su:
    su username
    Get the screen:
    screen -DDRR

    Howto mount disk image with partitions

    Check the number of cylinders from the original disk (e.g. with cfdisk) and check the image properities:
    fdisk -l -u -C <#cylinders> dd.image

    Mount the image with right byte-offset:
    mount -o loop,offset= dd.image mnt

    Howto monitor ip-traffic


    Adding firewall (or anyother script) to start automatically

    ln -s ../init.d/connect_router rc2.d/S20connect_router
    Do the same for levels 2-5. S means Start so you might want to have also 0-1 and 6 run levels a script with K20connect_router (to Kill).

    This is of course wrong way to do it. How it should be done:
    update-rc.d connect_router defaults
    update-rc.d connect_router start 99 2 3 4 5 . stop 99 0 1 6 .
    To test the script, you can use:

    Playing with network interfaces

    apt-cache show netenv

    How to change default route? In the ifconfig there is defined what to do before and after interface is put down, e.g. postdown etc.

    Search files from packages

    How to findout in which package file belongs to:
    dpkg -S filename

    How to findout which files belong to a packet:
    dpkg -L packetname

    Usb2serial configuration

    apt-get install usrp
    To test:
    cat /dev/ttyUSB0

    aclocal: not found

    Install automake.
    autoconf -- to get autoheader,autoconf
    libtool -- to get libtool, libtoolize 

    Matlab is missing a function

    file exchange toolbox: fxsearch

    Howto find out what application is using your port

    Who is using port XXX:
    fuser -n tcp XXX
    List all ports being used:
    netstat -nlp

    IRC in ipv6 with irssi

    Set the ipv6 hostname that you have:
    /set hostname
    Connect to the server that supports ipv6:
    /server -6

    SMART IDE hard disk info

    aptitude install smartmontools
    Show device info (does not work for USB disks):
    smartctl -a /dev/sda

    Joomla transfer to new server

    1) Download latest stable version of joomla and install it
    2) Load the mysqldump of your old site to the new database.
    3) Copy files that you are missing from the old system (modules/mod_header_image*, images/*, templates/?*)

    Installing kernel from ubuntu/debian package

    Install kernel:
    apt-get source linux-image-2.6.20-16-386
    Install sources (needed e.g. to compile truecrypt):
    apt-get source linux-image-2.6.20-16-386

    hostname change

    and set
    hostname [new_hostname]

    Inventory computers

    Install these packages:
    aptitude install dmidecode libio-zlib-perl libxml-simple-perl libnet-ip-perl libnet-ssleay-perl libwww-perl

    Look strings inside binary file (e.g. jpg)

    strings kuva.jpg | less

    charset data for locale

    luit searches locales from:
    but they are actually located in:

    xterm encoding

    xterm -en iso-8859-15

    change sender in pine

    Select SETUP and C (Config). Customize the line:
    customized-hdrs=From: email.address@somewhere.the

    Check web sites links validity

    linkchecker --no-warnings

    Using dump/restore

    First edit /etc/fstab to include "1" to the places that you want to backup. Otherwise keep/set to zero the column dump.

    Create a zero level dump first:
    dump 0uf dump_level0.dump /

    You can list the contents of the dump:
    rrestore -tf 2007_08_29_yebbey_l0.dump

    Modify SQL table

    Check current settings:
    describe events;

    Dump/restore one mesql database

    mysqldump [databasename] -p -u root | gzip -c > mysql_dump.gz
    gzip -cd mysql_dump.gz | mysql -u root -p

    Add a new user for mysql table

    Add without DROP/CREATE priviledges:
    grant INSERT,DELETE,UPDATE,SELECT on mydatabasename.* to myusername@localhost;
    Add also password:
    set password for myusername@localhost = password('mysecretpassword');

    Dump just data/structure

    Just structure:
    mysqldump -d --compact -u root -p yourdatabase > dump
    Just data:
    mysqldump -p -u root yourdatabase --no-create-info > dump
    Just data, one insert per row:
    mysqldump -p -u root yourdatabase --extended-insert=FALSE --no-create-info > dump

    Get more info about a file

    Display file or file system status:
    stat filename.end
    Determine file type:
    file filename.end

    php upload site

    Configure /etc/php5/apache2/php.ini:
    1. upload_max_filesize
    2. max_execution_time
    3. max_input_time
    4. post_max_size

    Pairing cellphone and laptop with bluetooth

    hcitool scan
    mknod /dev/rfcomm0 c 216 0
    rfcomm bind 0 1
    passkey-agent --default /etc/bluetooth/
    You can try the connection with e.g. konqueror, write:

    Send a sms from a command line

    gnokii --sendsms +358504137550 < message.txt

    Document search engine

    Creates a google type of document search engine, includes pdf:s, docs and text files for example.

    Make password


    Multipointer operating system

    Use mpx live cd and you will have operating system that supports e.g. two mouse pointers.
    Boots up usually directly and also programs which are not designed for multipointing work at least adequately.

    Load kernel module with specific parameters

    For example acer_acpi module with wireless=1 parameter.
    echo "options acer_acpi wireless=1" > /etc/modprobe.d/acer_acpi

    Automatic wireless wep network setup

    auto wlan0 iface wlan0 inet dhcp wireless-essid wireless-key s: open

    Easy to use firewall using iptables

    Uncomplicated FireWall:
    ufw enable
    ufw logging on
    sudo ufw allow 53/tcp
    sudo ufw allow ssh

    Continue partially send scp file

    rsync --partial file.tar.bz2

    vmware in ubuntu hardy heron howto

    Packages required:
    aptitude install build-essential linux-kernel-devel linux-headers-generic xinetd
    Run install (with normal settings):
    Copy few files to right places:
    cp /lib/ /usr/lib/vmware/lib/
    cp /usr/lib/ /usr/lib/vmware/lib/
    Locate your virtual machine and edit the vmx file in this folder and add the following line:
    svga.maxWidth = "1280"
    svga.maxHeight = "800"
    You can also try if above does not work:
    sudo gedit ~/vmware/preferences
    - Now where it says:
    pref.autoFitFullScreen = "fitHostToGuest"
    change it to:
    pref.autoFitFullScreen = "fitGuestToHost"

    vmware USB enable

    Uncomment lines 42-45 starting with #mkdir p....

    Remove duplicate lines

    Remove duplicate acronyms (-f == ignore case)
    sort -f acronyms_unsorted.tex | uniq > acronyms.tex
    Display duplicate acronyms:
    sort acronyms.tex | uniq -dc

    Install fglrx in ubuntu

    Install restricted modules:
    aptitude install linux-restricted-modules-`uname -r`
    sudo dpkg-reconfigure -phigh linux-restricted-modules-`uname -r`
    sudo insmod /lib/modules/`uname -r`/volatile/fglrx.ko

    Boot without password

    At grub-boot loader screen. Select Recovery mode the version of the kernel that you wish to boot and type e for edit. Select the line that starts with kernel and type e to edit the line.

    Go to the end of the line and type init=/bin/bash as a separate one word (press the spacebar and then type init=/bin/bash). Press enter key to exit edit mode.

    Play encrypted dvds

    with vlc, choose disc and dvd and volaa.

    Save your sound mixer settings in reboot

    aptitude install alsa-utils
    alsactl store
    Automatic version:
    # load/unload the volume settings on startup/shutdown install snd-driver-name /sbin/modprobe \ --ignore-install snd-driver-name;/usr/sbin/alsactl restore remove snd-driver-name /usr/sbin/alsactl \ store;/sbin/modprobe --ignore-remove -r snd-driver-name

    for loop in bash

    for i in `seq 1 9`;do wget$i.jpg;done

    Check disk health status

    smartctl -H /dev/hda smartctl -l error /dev/hda,

    Capture video with sound

    Setup the mixer settings e.g. using gnome-alsamixer. Make sure that "Mix" and "Capture, Rec" are selected.
    recordmydesktop -x 100 -y 100 -width 300 -height 300 -o output.ogg
    End the recording by Ctrl+C.
    3D accelerated parts require that --full-shots parameter is used.
    recordmydesktop -x 150 -y 120 -width 700 -height 500 -fps 30 --full-shots -o output.ogg

    Make windows compatible avi

    Does not work as PDF embedded movie:
    mencoder input.avi -o out.avi -ovc lavc -lavcopts vcodec=msmpeg4v2 -oac copy

    Compare two md5sum files

    Return the lines that are mentioned in first file but not in second.
    sort a >aa; sort b >bb; diff aa bb | sed -n '/^ Don't care if file is located in different directory:
    sort a | sed -n 's/\/.*\///p' > aa;sort b | sed -n 's/\/.*\///p' > bb; diff aa bb | sed -n '/^ Also this works instead of 's/\/.*\///p':

    Compare just the md5sums:
    sort a | sed -n 's/ .*//p' > aa;sort b | sed -n 's/ .*//p' > bb; diff aa bb | sed -n '/^

    Match lines starting with k and print

    sed -n '/^k/p'

    Add space before string

    ls -1 | sed -n 's/^./ \0/p'

    Kill all processes accessing a mounted partition

    fuser -km /home/ssheikki/mnt

    Debugging functions in matlab/octave

    Add a breakpoint in function "test.m" in line 28:
    dbstop test 28
    Note! Returns the line where the breakpoint was actually set.
    Go to the next line in debug mode:

    Download all packages installed to your system

    dpkg --get-selections | sed -n 's/..install$//p' | perl -pi -e 's/^\s*(\S.*\S)[ \t]*$/$1 /' | perl -p -e 's/\n//' > packages
    Edit aptitude download in the start of the file of packages.
    sh packages

    Replace space with underline in filenames

    rename "s/ /_/g" *

    Add prefix in the front of the name

    rename 's/(.+)/prefix-$1/' *.jpg

    Remove prefix from the front of the name

    for f in prefix-*; do mv "$f" "${f#prefix-}"; done

    Run firefox, etc in 32bit mode

    dchroot -c ia32 -d firefox
    dchroot -c ia32 -d gmplayer

    Sort according to second column

    sort +1 -2 filename.txt

    Install text to speech system

    aptitude install festival
    echo "Speech to text. It works?" | festival --tts
    You might want to install some festvox-* packages:
    echo "Kuka mina olen?" | festival --tts --language spanish
    echo "Kuka mina olen?" | festival --tts --language finnish

    Get info about your soundcard

    Cards recognized:
    aplay -l
    asoundconf list
    Default clock etc. parameters:
    modinfo module_name, e.g. modinfo snd_atiixp

    Compile kernel with initrd

    make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
    See also:

    Manage your iPOD in linux


    Run oss designed program using alsa

    aoss program_name

    arping in debian/ubuntu

    aptitude install arping
    arping 00:0a:e4:e1:04:b9

    Capture mms stream from net

    mplayer mms://example.con/example12a.wmv -dumpstream -dumpfile example12a.wmv

    Remove pages from pdf files

    aptitude install pdftk
    Remove pages 1,2 and 10-14:
    pdftk input.pdf cat 3-9 15-end output output.pdf

    Combine pages from several pdfs into one

    pdftk A=input1.pdf B=input2.pdf cat B1-2 A3-end output combined.pdf

    Compare contents of two directories

    To see differencies in the contents of two directories:
    diff -rq dirA dirB
    Note, the comparison is recursive, so also contents of subdirectories are compared.

    Howto install display drivers

    Get envy.deb
    Install it... and run "envy -t".

    Config alsa

    You might get error like this:
    alsamixer: function snd_ctl_open failed for default: No such device

    Compile programs faster

    Display planet as background

    xplanet -latitude 40

    Install Nvidia/ati drivers

    aptitude install envyng-core
    envyng -t

    Trace what system calls a program does

    strace -eopen alsamixer

    Update PCI ID list


    Missing initram causes kernel panic

    Notice something like VFS mount failed
    update-initramfs -u -k

    Change default audio card


    Show progress of suspended dd

    kill -SIGUSR1 %1

    Protect yourserver from attacks

    - aide (files) - tiger (services) - rootkit (rootkits)

    Loading irssi scripts

    /script load scriptassist
    /scriptassist install morse

    Install additional packages to debian-stable - backports

    Add this line to /etc/apt/sources.list:
    deb etch-backports main contrib non-free

    John the Ripper

    Check that passwords are strong:
    unshadow /etc/passwd /etc/shadow > johnfile
    john johnfile

    Password strength check in login

    aptitude install libpam-cracklib
    Add to the services you want in /etc/pam.d/(e.g. common-password, ssh and login) this:
    # Be sure to install libpam-cracklib first or you will not be able to log in
    password required retry=3 minlen=10 difok=3
    password required use_authtok nullok md5 remember=3

    Convert dos/windows files Unix format

    Basically change the carriage return:
    aptitude install tofrodos
    dos2unix/fromdos and unix2dos/todos commands.

    Prevent hacker to bombing your computer

    aptitude install fail2ban
    aptitude install denyhosts
    "Monitors log files (e.g. /var/log/auth.log, /var/log/apache/access.log) and temporarily or persistently bans failure-prone addresses."
    In jail.conf, change:
    # Default action to take: ban & send an e-mail with whois report 
    # and relevant log lines to the destemail.
    action = iptables[name=%(__name__)s, port=%(port)s]
             mail-whois-lines[name=%(__name__)s, dest=%(destemail)s, logpath=%(logpath)s]
    enabled = true
    port    = ssh
    filter  = sshd
    logpath  = /var/log/auth.log
    maxretry = 12
    bantime = 3600
    findtime = 600
    ignoreip =

    You wanna track bugs?

    Install mantis:

    Want to send email outside in Linux

    Configure global internet delivery:
    dpkg-reconfigure exim4-config
    Test e.g. with:
    mail -v -s Test

    Make a package from source code that you can install/deinstall

    aptitude install checkinstall
    checkinstall make install

    Print two(or more) pages per sheet pdf

    psnup -2 >

    Convert audio files (e.g. wav) and adding effects with sox

    aptitude install libsox-fmt-all
    Play file with effect:
    play input.wav chorus 0.5 0.9 50 0.4 0.25 2 -t 60 0.32 0.4 2.3 -t 40 0.3 0.3 1.3 -s Convert file:
    sox input.wav output.wav chorus 0.5 0.9 50 0.4 0.25 2 -t 60 0.32 0.4 2.3 -t 40 0.3 0.3 1.3 -s

    Building and testing software projects automatically

    Hudson, versionin system and cron compatible java based open-source software:

    Creating test cases and plans

    Test Case Management tool:

    Skype etc., howto install

    Check Medibuntu:

    Configure nvidia xorg.conf

    gksu nvidia-settings

    Wireless network-manager in Linux

    network-manger and cnetworkmanager.

    Use calibrated joystick

    aptitude install joystick
    jscal -c /dev/input/js0

    Festival is not working

    If festival returns:
    Linux: can't open /dev/dsp
    Add in the end of /usr/share/festival/festival.scm
    (Parameter.set 'Audio_Method 'Audio_Command)
    (Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")

    Print status of files in cvs like with svn status

    alias cvsstatus="cvs status * 2>&1 | grep Status: 2>&1 | grep -v \"Up-to-date\" 2>&1 | grep -v \"cvs add\""

    Check user idle time in irssi

    wii the_username

    Play videos with multithreaded mplayer

    alias mplayer='mplayer -lavdopts threads=2 -vo gl2'
    and play normally with mplayer.

    See what is happening in system level on program

    strace - trace system calls and signals
    strace whois
    strace whois 2>&1 | grep send

    Recursive ftp upload

    aptitude install ncftp
    mput -R *

    LAN over bluetooth rfcomm/PPP

    Add in /etc/ppp/peers/dun this:
    Start the service daemon:
    dund --listen --persist --msdun call dun
    Note! You dont need to even create bond with the device.

    Load additional programs in IRSSI

    /load ~/irssi/
    /scriptassist search [program_name]

    Use bluetooth headset in Linux

    Insert this in .asoundrc file:
    pcm.!default {
            type bluetooth
            device "00:0D:44:0A:6D:C3"
            profile "auto"

    Stop/continue, abort running process

    kill -STOP 
    kill -CONT 
    kill -ABRT 
    For more commans, see "man kill".

    Netcat echo server

    Server that echoes back all what it receives:
    mkfifo responsepipe && cat responsepipe | nc -l -p 5000 > responsepipe
    Print also what received:
    cat responsepipe | nc -l -p 5000 | tee responsepipe
    Print and log what also received:
    cat responsepipe | nc -l -p 5000 | tee responsepipe responses.log

    Save joystick calibration

    After calibration, get settings:
    jscal -p /dev/input/js0
    Then write settings later:
    jscal -s 6,1,1,126,126,12484989,9256113,1,0,118,118,11422437,6547006,1,0,130,131,6972137,7894920,1,0,108,108,7254791,7354172,1,0,0,0,5

    Dynamic (execution) and static (linking) library paths

    Dynamic library path are managed using ldconfig or LD_LIBRARY_PATH variable.
    Static libraries are managed using -L compiler flag.

    Show RS232 port settings

    stty -a -F /dev/ttyUSB0
    Note! Does not seem to show RTS bit state.

    Strip libraries for release

    You can strip only debug info:
    strip --strip-debug libExample.a

    Request web page with random address from wanted ip using nc

    nc 80
    GET /yourstuffmorehere HTTP/1.1

    Ad-hoc mode in client computer

    iwconfig wlan0 essid SERVER_ESSID mode Ad-hoc
    ifconfig wlan0 netmask up
    route add -net default gw SERVER_IP netmask wlan0

    (Re)Install grub2

    Mount your linux partition to /mnt and:
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys
    dpkg-reconfigure grub-pc
    Unmount everything and reboot.

    Add manually Windows to grub2

    Edit /etc/grub.d/40_custom and add:
    menuentry "Windows" { insmod ntfs set root=(hd0,1) search --no-floppy --fs-uuid --set YOUR_UUID_FROM_DEV_DISK_BY_UUID chainloader +1 }

    Taking time with c/c++

    struct timespec start, stop;
    double duration= (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec) / 1000000000.0;
    printf("time elapsed = %.9f s", duration);
    g++ -lm -Wall -lrt main.cpp

    Piper errors or stderr e.g. to grep

    yourprogram 2>&1 | grep -v "warning that and that"

    x264 video encoding in Linux

    Install ffmpeg:
    Encode eg. p3140032.avi to p3140032.mp4:
    ffmpeg -i p3140032.avi -pass 1 -vcodec libx264 -vpre fast_firstpass -b 512k -bt 512k -threads 0 -f rawvideo -an -y /dev/null
    ffmpeg -i p3140032.avi -pass 2 -acodec libfaac -ac 2 -vcodec libx264 -vpre fast -threads 0 output.mp4

    Find out information about video file

    ogminfo, MP4info, mkvinfo (or mkvmerge with the "-i" switch)

    Check what formats and codecs ffmpeg supports

    ffmpeg -formats
    Top choises:
     DE avi             AVI format
     DE matroska        Matroska file format
      E mp4             MP4 format
    ffmpeg -codecs
    Top choises:
     D V D  h264            H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
      EA    libfaac         libfaac AAC (Advanced Audio Codec)
      EA    libmp3lame      libmp3lame MP3 (MPEG audio layer 3)
      EV    libx264         libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
     DEV D  mjpeg           MJPEG (Motion JPEG)
     DEVSDT mpeg1video      MPEG-1 video
     DEVSD  msmpeg4         MPEG-4 part 2 Microsoft variant version 3
     DEV D  qtrle           QuickTime Animation (RLE) video
     DEA    vorbis          Vorbis
     DEVSD  wmv2            Windows Media Video 8

    Digital camera video encoding howto (H.264/MPEG-4 AVC + Vorbis ogg)

    ffmpeg -y -i $inputvid -b 1.5M -bt 4M -vcodec libx264 -pass 1 -vpre fastfirstpass -an $inputvid.mkv
    ffmpeg -y -i $inputvid -b 1.5M -bt 4M -vcodec libx264 -pass 2 -vpre hq -acodec vorbis -aq 60 -ac 2 $inputvid.mkv

    Start several programs into one screen

    Lets assume there is script with takes output file as parameter:
    screen -d -m -t test bash out1.txt
    screen -X screen -t test2 bash out2.txt -p 1
    screen -X screen -t test3 bash out3.txt -p 2
    In file run_screens:
    screen 1 bash out1.txt
    screen 2 bash out1.txt
    screen -d -m -c run_screens

    Count the lines of code and estimate price

    sloccount ~/project_name

    Get previous version of file for Subversion

    If current version of the file is 7919:
    svn update file.hpp -r 7918

    Configure cups printers

    Go to:

    Resize pager window in enlightement

    Press middle mouse button and alt on the pager window. Then just move the mouse to resize the window.

    Serial/RS232 communication in Linux


    Adjust wrong eps image bounding box


    Change the default wordlist e.g. for ispell

    sudo select-default-wordlist
    and ispellconfig
    In emacs: M-x ispell-change-dictionnary
    Then M+x and ispell should work for spell checking in emacs with wanted language.
    Make sure that you have the correct i-dictionaries installed, e.g. ibritish.

    Upgrade ubuntu to new version


    Disable network-manager and do things by hand

    /etc/init.d/network-manager stop
    ifup wlan0

    Compressing video to mpeg4 with default ubuntu codec

    ffmpeg -ss 13 -t 5 -y -i $input.avi -vcodec mpeg4 -b 1.5M -bt 4M -r 25 -ar 44100 output.mkv
    You might have audio sync problems, then follow this:
    So basically above would be:
    ffmpeg -ss 13 -t 187 -y -i $input.avi -itsoffset -14 -i $input.avi -map 1:0 -map 0:1 -b 1.5M -bt 4M -r 30 -ar 44100 $output.avi

    How to convert jpg, etc files to eps to be used in latex

    convert input.jpg output.eps2

    Join or append avi/video files in Linux

    mencoder -oac copy -ovc copy -o output.avi input1.avi input2.avi

    grep recursively text files only

    grep -R search_string --include '*.txt' *

    Check with arping if server is up or down

    arping -I wlan0
    Unicast reply from [00:22:FA:0C:69:E0] 51.373ms
    Unicast reply from [C8:97:9F:C3:85:84] 133.760ms

    Extract images from PDF document

    pdfimages -j foo.pdf images

    Flip your upside down web camera image

    Do these:
    echo -e "\n# libv4l PPA\ndeb `lsb_release -c | awk '{print $2}'` main" | sudo tee -a /etc/apt/sources.list
    sudo apt-key adv --recv-keys --keyserver C3FFB4AA
    sudo aptitude update
    sudo aptitude install libv4l-0
    LD_PRELOAD=/usr/lib/libv4l/ application_name

    Password for '(null)' GNOME keyring: failure when using svn

    killall gnome-keyring-daemon
    rm -rf~/.gnome2/keyrings

    Find out which program is using your soundcard

    lsof | grep snd

    Show which version was edited and by whom in svn

    svn annotate filename.cpp

    List lines that are common in two files

    Sort the two files and then run:
    comm -1 -2 sorted_file1 sorted_file2

    Set default file mask for new files

    Set mask 755 for new files (777-022=755):
    umask 0022

    Take a screenshot with mplayer

    mplayer -vf screenshot yourvideo.avi
    Then press just "s" whenever you want a screenshot.
    Remember that with "." you can go frame by frame forward.

    Profile your program, check which part is taking the power

    compile with -pg switch when using gcc.
    Add also debugging symbols (-g) and remove optimization (-O3) etc.
    It creates a gmon.out file which contains profiling info.
    The gmon.out can be examined with gprof or kprof tools.
    Check also gcc parameter gcov and program with same name. Used for code coverage (to see what parts have been used).
    Note! gprof does not support threads!
    For that purpose, might be good to check profiler.

    Howto turn webcamera upside down

    LD_PRELOAD=/usr/lib/libv4l/ firefox
    See also settings in:
    LD_PRELOAD=/usr/lib/libv4l/ v4l2ucp

    How to setup a free video conferecing system

    For this you need a server that has three ports visible to the internet.
    Then check and add repositories to your ubuntu and aptitude install. In 15 minutes you are good to go. The people joining the conference need only web browser to be available.

    Linux ext3 filesystem format options

    If we have 1TB disk and we use "mkfs.ext3 -m0 -T largefile /dev/sda1" to create it, we get:
    Block size 4kB, inode size 256B, and bytes-per-inode (-i) parameter ~1MB.
    /dev/sda1 976457320 204568 976252752 1% /home/ssheikki/mnt
    /dev/sda1 954k 11 954k 1% /home/ssheikki/mnt
    Instead, if we use "mkfs.ext3 -m0 /dev/sda1" to create it, we get:
    Block size 4kB, inode size 256B, and bytes-per-inode (-i) parameter ~16kB.
    /dev/sda1 961432072 204568 961227504 1% /home/ssheikki/mnt
    /dev/sda1 62M 11 62M 1% /home/ssheikki/mnt
    Difference is ~15GB, which is 1.5% of the disk space.
    Block size is the smallest block that can be taken my any file in the file system.
    Bytes-per-inode will in the end tell how many inodes will be created. So in order for your inodes to be enough, your average filesize should be this size.
    Inode size tells size of one inode. You can calculate the space that your inodes take with this formula (=disk size/bytes-per-inode*inode size).

    Check inode size of partition

    sudo tune2fs -l /dev/sda1 | grep Inode

    Ext2IFS compatible ext2/ext3 filesystem

    To get compatible filesystem with Ext2IFS, use:
    mkfs.ext3 -m0 -T largefile -I 128 /dev/sda1
    You will get:
    bytes-per-inode:          1MB
    Block size:               4096
    Inode size:               128
    Note that supports the larger 256 inode size!

    Configure firefox settings

    write in address bar about:config

    Check if some nameserver can direct your domain


    Convert black and white bitmaps to vector graphics


    Convert file to utf8 or latin1

    iconv -t ISO8859-1 -f UTF-8 parties.sql > parties2.sql

    Howto determine charset encoding

    file -i parties.sql
    enca -L none parties.sql

    Show processes that are using http 80

    sudo fuser -n tcp -v 80

    Learn about printf syntax

    man 3 printf
    printf("%*d", width, num);

    zenity --info --text="wat"

    Make popups in Linux GUI (KDE?)

    Rescue a partition that has bad sectors

    There is two programs dd_rescue and ddrescue. It seems that ddrescue was able to recover all but 8kB and dd_rescue all but 127kB. Install ddrescue like this:
    aptitude install gddrescue
    and run it like this:
    sudo ddrescue -v -r -1 /dev/sdb1 sdb1.ddrescue /home/ssheikki/ddrescue_log.txt

    Encfs howto

    aptitude install encfs fuse-utils
    modprobe fuse
    adduser ssheikki fuse
    encfs /home/ssheikki/encfs /home/ssheikki/mnt
    fusermount -u /home/ssheikki/mnt

    Adding subtitles to a video

    aptitude install gnome-subtitles
    Create test.srts omething like this:
    00:00:00,000 --> 00:02:57,040
    mencoder -sub -subpos 0 -subfont-text-scale 7 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=800:vhq -oac copy -o test2.avi test.avi
    If you want to hardcode two subtitles, use first a raw avi and later encode:
    sudo mencoder -sub -subpos 0 -subfont-text-scale 7 -ovc raw -vf format=yuy2 -oac copy -o mnt/test2.avi test.avi sudo mencoder -sub -subpos 90 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=800 -oac copy -o test3.avi mnt/test2.avi

    Add character on start of each line

    If you want to add "> " to start of each line:
    sed -i -e 's_.*_> &_' file_to_be_processed.txt

    List files that were recently modified

    In last 30mins:
    find / -mmin -30

    Delete files that have size "1"

    Check first that all files are correct with this (note, shows all files if no hits found... behaviour of rm is different of course):
    find . -maxdepth "1" -type "f" -size "1" -print | xargs ls
    Then delete with this:
    find . -maxdepth "1" -type "f" -size "1" -print | xargs rm

    Extract audio from a video

    mplayer VIDEO.MTS -vc null -vo null -ao pcm:fast:file=output.wav

    Go in emacs to certain line

    Esc+x goto-line
    Esc-g g

    Add column to mysql table

    ALTER TABLE event_referer ADD COLUMN emailcrons tinyint NOT NULL DEFAULT '0' AFTER email;
    Result might be something like this (viewed with describe event_referer):
    | Field       | Type                      | Null | Key | Default             | Extra                       |
    | emailcrons  | tinyint(4)                | NO   |     | 0                   |                             |
    If somethings goes wrong, use DROP COLUMN:
    ALTER TABLE event_referer DROP COLUMN emailcrons;
    Note that size after tinyint is not "real size" but "mental reminder of how big the field should be":
    ALTER TABLE event_referer ADD COLUMN showanswers tinyint(3) DEFAULT '0';

    Check account password and other expiration details

    chage -l ssheikki

    Mp4 to avi conversion with ffmpeg

    ffmpeg -i ROB-11-002_video1.mp4 -vcodec mpeg4 -acodec ac3 -ar 48000 -ab 192k -ac 6 -sameq output.avi

    Resize ps/pdf document

    ps2pdf -sPAPERSIZE=a4 document.pdf

    Get own git repository

    git clone ssh://
    To use a short name:
    git remote add giraffi ssh://
    git fetch giraffi
    git merge giraffi/master

    jpegs to avi

    sudo mencoder "mf://*.JPG" -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

    pine: How do I change my 'From:' line?

    From Pine's [M]AIN MENU, choose [S]etup, then [C]onfig. Move down to the customized-hdrs option. Press "A Add Value". Use the format:
    From: "My Real Name"

    List size of all files (also hidden) in directory, but not ..

    du -sk .[!.]* *| sort -n

    Maven tips

    Build javadocs:
    mvn javadoc:javadoc OR mvn clean site

    Jpg/image to A4 pdf

    convert passport.jpg passport.pdf
    acoread passport.pdf
    Then just print the pdf as A4 into file.

    Extract ip address from ifconfig command

    ifconfig wlan0 | grep "inet addr:" | sed -n 's/.*addr:\([0-9.]*\) .*/\1/p'

    Encrypt/decrypt file

    openssl enc -md sha -bf-cfb -e -in tunnusluvut.png.enc -out tunnusluvut.png openssl enc -md sha -bf-cfb -d -in tunnusluvut.png.enc -out tunnusluvut.png

    Find open ports or what ports are process is using

    lsof | grep TCP

    Viewing CR2 files in linux

    f-spot view
    aptitude install gnome-raw-thumbnailer

    Rescale your video

    mencoder GOPR2132.MP4 -o out2.avi -ss 341 -endpos 30 -ovc lavc -lavcopts vcodec=msmpeg4v2 -vf scale=640:480 -oac copy

    svn admin dump/load

    Recommended way to serialise svn and transfer it to another place.
    bzcat ../ssheikki-svndump.bz2 | svnadmin load jeppe

    Howto create bootable USB disk

    Download image and config it to usb disk with:

    Eclipse and Vaadin

    1) If something is screwed up
    * Select your project and press right key
    * Maven -> Update Project Configuration
    2) If you want to get maven project from svn
    * Select import in eclipse
    * write maven and select "existing maven projects"

    Host your nameservers with minimal fuss

    aptitude install maradns

    Check that your c-code does not have problems

    aptitude show splint

    List all files that are symbolic links

    find . -type l -print
    and delete them
    find . -type l -exec ls '{}' \;

    Repeat same command every X seconds

    watch -n 0.1 ls -laF /tmp

    Torrent client that supports magnet links

    qBittorrent (at least v.2.2.5)

    Interlaced 50fps HD HTS to avi or mp4

    Install latests ffmpeg:
    Requires to compile x264 also... and probably many others.

    With ffmpeg that supports filters:
    ffmpeg -i in.MTS -vf yadif=1 -acodec ac3 -ab 192k -vcodec mpeg4 -f mp4 -y -sameq out.mp4

    With x264 (which is the best option):
    ffmpeg -threads 2 -i input.MTS -vcodec libx264 -filter:v yadif -b 3000k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -flags +loop -acodec libmp3lame -ar 48000 -ab 128k -ac 2 output.avi
    With more high quality presets:
    ffmpeg -threads 2 -i 00001.MTS -vcodec libx264 -filter:v yadif -b 3000k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -flags +loop -preset slow -crf 22 -acodec libmp3lame -ar 48000 -ab 128k -ac 2 outputfile.avi

    Play interlaced video with mplayer

    mplayer -vf pp=lb 00003.MTS

    Make DVD iso file

    mkisofs -o dvd.iso -r -J -V "Name of the DVD" -publisher "Name Lastname" -graft-points "video.avi=/path/of/first.avi" "pictures=/path/of/pictures/" "README=/path/of/README"

    Burn a DVD without making iso image first (works in Linux and windows, but not with Mac?)

    growisofs -dvd-compat -speed=1 -Z /dev/dvd -r -J -V "Name of the DVD" -publisher "Name Lastname" -graft-points "video.avi=/path/of/first.avi" "pictures=/path/of/pictures/" "README=/path/of/README"

    Commit files to git repository

    Commit just a specific file:
    git add changed_file.txt
    git commit -m "Small improvements."
    Commit all changed tracked file:
    git commit -m "Small improvements." -a
    Check where to fetch/push
    git remote -v

    Get DPI resolution of your display

    xdpyinfo | grep resolution
    and you should get (aut-101):
    resolution: 102x102 dots per inch
    Change it:
    xrandr --dpi 138/eDP1

    Use HP scanner

    aptitude install hplip-gui
    Install scanner/printer using the IP.
    Use it!

    Make good automatic passwords

    sudo apt-get install makepasswd
    makepasswd --char=10

    Recover NTFS files from corrupted filesystem

    Wondershare data recovery, tested by Eke.

    Scp files but without symlinks

    rsync --progress -avhe ssh root@ .

    Configure internet in Linux

    gnome-control-center network

    Get/change display DPI resolution

    xdpyinfo | grep inch
    xrandr --dpi 138/eDP1

    Change backlight settings

    sudo intel_backlight 20

    Adjusting sound volume from command line

    amixer -q set Master toggle unmute amixer -q set Master 2+ unmute && amixer -q set Speaker 2+ unmute && amixer -q set Headphone 2+ unmute
    amixer -q set Master 2- unmute && amixer -q set Speaker 2- unmute && amixer -q set Headphone 2- unmute

    Using Bumblebee in Linux

    optirun nvidia-settings -c :8
    To see if Nvidia is in use:
    cat /proc/acpi/bbswitch

    Find what eats power from your laptop


    Put laptop in power saving mode

    8.14 Watts on Average with Standard Deviation 0.18 sudo pm-powersave true 8.38 Watts on Average with Standard Deviation 0.15 Note: Does not seem to be useful.

    Measure laptop power consumption

    sudo add-apt-repository ppa:colin-king/powermanagement sudo apt-get update sudo apt-get install powerstat powerstat

    Grub boot selections for UX32VD

    8.96 Watts on Average with Standard Deviation 0.25
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pcie_aspm=force drm.vblankoffdelay=1 i915.semaphores=1 nmi_watchdog=0"
    8.26 Watts on Average with Standard Deviation 0.19
    Turning off wireless and keyboard:
    7.21 Watts on Average with Standard Deviation 0.48
    Turning off the display:
    6.70 Watts on Average with Standard Deviation 0.15

    Monitor battery charging

    gnome-power-statistics Maybe also: battery-stats-collector

    Monitor CPU usage


    Get display setting info

    sudo get-edid | parse-edid

    Changing display resolution in xorg

    Graphical tools: lxrandr, arandr
    cvt 1920 1080 60 xrandr --newmode xrandr --addmode eDP1 "1920x1080_60.00" xrandr --output eDP1 --mode "1920x1080_60.00" --rate 60 --fbmm 295x166

    Change java environment

    sudo update-alternatives --config java sudo update-alternatives --config javac

    Show files that changed between revision 207 and 209

    svn diff -r 207:209 --summarize
    More details:
    svn diff -r 207:209

    Join avis and compress to mp4

    mencoder -ovc copy -oac copy input*.AVI -o joined.avi kdenlive # Install before x264, etc. properietary codecs # These did NOT work properly: ghb # avimerge -i input*.AVI -o joined.avi avisync -o synced.avi -i joined.avi -n 90 # 30fps => 3.6s delay

    Mounting WebDAV to folder

    sudo apt-get install davfs2 && sudo modprobe coda mount.davfs http://localhost/owncloud/remote.php/webdav/ mnt

    Collect data from running Linux

    aptitude install collectd sudo cp -R /usr/share/doc/collectd/examples/collection3 /var/www/ sudo apt-get install librrds-perl libconfig-general-perl libhtml-parser-perl libregexp-common-perl http://localhost/collection3/bin/

    recordmydesktop and audio also

    apt-get install pavucontrol pavucontrol # change in Recording tab, ALSA capture from to "Monitor of..." recordmydesktop -x 50 -y 50 --width 640 --height 320 --fps 30 --full-shots -o output.ogg --device pulse

    How to autorotate pictures based on exif data

    jhead -autorot *.jpg

    Display file info (such access, creation date)

    stat yourfile.txt

    Add sudo rights to users, no password required


    Encode x264 video without encoding audio

    Preferred way is to require good quality: ffmpeg -i input.avi -c:v libx264 -preset veryslow -crf 18 -c:a copy output.mkv If original is 582MB, then veryslow is 152MB (26%) and slow is 163MB (28%). If you want to have fixed file size: ffmpeg -threads 4 -i joined.avi -vcodec libx264 -filter:v yadif -b 3000k -cmp +chroma -g 250 -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -flags +loop -acodec copy output.avi

    Stabilise videos in Linux

    melt input.avi -filter videostab4 shakiness=4 -consumer xml:temp.xml all=1 real_time=-2 melt temp.xml -audio-track input.avi -consumer avformat:output.mp4 vcodec=libx264 crf=18 tune=film preset=slow

    Editing Olympus u850SW videos with kdenlive

    It seems that the basic audio format "uncompressed PCM (mono, 8000 Hz)", does not work well with kdenlive. There is strange noise every now and then. One solution is to convert the videos to use lossless flac codec:
    ffmpeg -i PA100038.AVI -c:v copy -c:a flac ../PA100038.AVI
    You get good quality output at least with Theora codec.

    How to backup remote svn repository

    svnadmin create newrepo echo '#!/bin/sh' > newrepo/hooks/pre-revprop-change chmod 755 newrepo/hooks/pre-revprop-change svnsync init file:///home/ssheikki/Desktop/newrepo --source-username=ssheikki --sync-username=ssheikki svnsync sync file:///home/ssheikki/Desktop/newrepo --source-username=ssheikki --sync-username=ssheikki --sync-password=syncPassword

    Scrolling buffer in screen

    Press Ctrl+A + [ Press esc to return to normal mode.

    Check if nameservers are working correctly

    dig dig Your IP should be found in the ANSWER section.

    How to add site in apache2 web server

    Add entry to /etc/apache2/sites-available
    sudo a2ensite service apache2 reload

    Encrypt/decrypt file in Linux

    gpg -c yourfile.tar gpg yourfile.tar.gpg

    HDR images/photos


    Random timestamp to epoch in Linux

    echo 29/Mar/2010:12:31:04 | timestamp=`sed 's/\// /g;s/:/ /'`; date --date=$timestamp +%s

    Start new screen versus new screen window

    screen -S "newscreen" -d -m bash -c "sleep 100" screen -t "newwindow" bash -c "sleep 100"

    Select screen window from command line

    screen -X select 6

    What your shell understand with a command

    type echo type ls type dir

    Create loop device of a file

    losetup /dev/loop0 targetfile

    Calculate lines of code in directory

    find . -name '*.c' | xargs wc -l find . -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" | xargs wc -l | sort -rn - find . \( -name "*.c" -o -name "*.h" \) -a ! -path "*2011*" | xargs wc -l | sort -rn - cloc /path/to/be/analysed1 /path/to/be/analysed2 \ --counted=/output/path/of/recognised/files/counted_files.txt \ --exclude-lang=m4,HTML, \ --exclude-dir=test,backup \ --not-match-f=\#

    Install another Linux in Ubuntu using VirtualBox

    apt-get install virtualbox
    Start virtualbox: virtualbox
    Follow instructions and provide the virtual image you want.
    Minimal 64bit Ubuntu 12.04.01 LTS server install took e.g. 1165MB disk space. After apt-get upgrade (latest kernel etc) 2019MB.
    After installing VirtualBox guest additions (to enable folder sharing between guest and host): 2146MB.
    Note: You can do port forwards or share disks to interact.

    Create virtual network between host and guest

    sudo apt-get install uml-utilities
    Add in host /etc/network/interfaces:
    auto tap0 iface tap0 inet manual up ifconfig $IFACE netmask up down ifconfig $IFACE down tunctl_user sudo ifup tap0
    Then you need to bridge to tap0 in the guest and add in guest's /etc/network/interfaces:
    auto eth1 iface eth1 inet static address netmask Now you should be able to access and, respectively.

    Install kernel modules (with m-a)

    apt-get install module-assistant dkms m-a prepare m-a update m-a a-i

    Print block device attributes

    sudo blkid

    Record Skype phone call in Linux

    This worked at least:
    1) Start skype
    2) Start audacity
    3) Make call and press record in audacity. You might need to set levels but worked ok directly.

    List all loop devices

    losetup -a Print next free: losetup -f

    Unmount detached network mounts

    mount -l

    Unmount device that says: "device is busy"

    lsof /dev/yourdevice ps aux | grep PIDwithOpenFile kill -9 PID # If it is e.g. terminal

    Doing calculations in command line Linux

    echo $((2*3)) # Integers only echo "6.6*2.4" | bc

    Protect your system from PHP flaws

    apt-cache show php5-suhosin

    Open .mobi files in Linu


    Website to make catchy animation videos

    Websites to make webpage mockups

    Analyse program execution details

    Linux Trace Toolkit (LTT)

    Save pdf with links

    links "http://some.url/pdf.pdf" Press "f" to save the file.

    Get certain range of bytes from a file

    curl -r -10 -o output.bin # get last 10 bytes curl -r 0-9 -o output.bin # get first 10 bytes

    Set resolution for 27p Dell U2713H 16/9 monitor

    cvt 2560 1440 30 xrandr --newmode "2560x1440_30.00" 146.25 2560 2680 2944 3328 1440 1443 1448 1468 -hsync +vsync xrandr --addmode HDMI1 2560x1440_30.00 xrandr --auto --output HDMI1 --mode 2560x1440_30.00 --above eDP1

    Browse S3 compatible cloud storages in Linux


    Create file with X MegaBytes of random content

    dd if=/dev/urandom of=XMB-file.dd bs=XM count=1 e.g. 10MB file dd if=/dev/urandom of=10M bs=10M count=1 dd if=/dev/urandom of=10M bs=1M count=10

    Do same command in multiple machines

    Use PuSSH: For example, generate random 10MB temp file to each computer: ./pussh -r lxbsp27[21-24] dd if=/dev/urandom of=/tmp/10M bs=1M count=10

    Opening and editing ROOT files (.root)

    Use TBrowser: root root [0] new TBrowser

    Get summary statistics of each protocol

    netstat -s

    Updatedb when using encrypted home folders

    .mlocate/updatedb after this locate should find your files

    Get CPU temperature to be detected

    sensors-detect sensors

    Open port using iptables

    iptables -I INPUT -p tcp --dport 1094 -j ACCEPT

    Find only binary files

    find . -executable -type f find -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print

    Show info about a file


    Direct all output to a file

    command &> file.txt

    Divide float numbers in Linux

    echo "scale=3;6.6/2.4" | bc

    Print file but skip n lines from start

    tail -n+2 file.txt

    cmake and gdb

    Add in CMakeLists.txt: set(CMAKE_BUILD_TYPE Debug) break davix_rw_test.cpp:40 run and then use next or step/s to walk through the interesting code. Other convenient commands: list, print , set = 3, finish Use gdb history, add file: ~/.gdbinit set history filename ~/.gdb_history set history save

    Show your bash commands

    set -x set +x

    Configure ethernet connection between two computers

    1st computer with network card eth0 (e.g. Ubuntu): ifconfig eth0 netmask broadcast 2nd computer with network card p6p1 (e.g. SL6): ifconfig p6p1 netmask broadcast Also disable automatic network configurations: /etc/init.d/NetworkManager stop /etc/init.d/ntworking stop

    Opening Graphical applications as a root

    xhost +local: beesu xeyes

    Check for rootkits/backdoors

    apt-cache show rkhunter apt-cache show chkrootkit

    Irc/irssi connect to a second irc server

    /server add -network freenode /connect freenode /join -freenode #

    Starts ls and date commands in two separete screen windows

    screen -dmS "hax" screen -S "hax" -p 0 -X stuff "ls$(printf \\r)" screen -S "hax" -X screen screen -S "hax" -p 1 -X stuff "date$(printf \\r)"

    Kill all detached screens

    kills () { for session in $(screen -ls | grep Detached | sed 's/ *\([0-9]\)\..*/\1/') do echo "Killing ${session}" screen -S "${session}" -X quit; done }

    Octave; change plot font and line sizes for presentation

    % Install: GNU Octave, version 3.6.4 (older ones won't probably work) plot(1:10);xlabel("example");ylabel("example");title("example"); fontsize=20; hx=legend('example');set(hx, "fontsize", fontsize) set([gca; findall(gca, 'Type','text')], 'FontSize', fontsize); set([gca; findall(gca, 'Type','line')], 'linewidth', 3); saveas(1, "presentation.jpg"); % Note! The Octave/gnuplot does not show the figure correctly but % the output is correct. Tested with gnuplot 4.4.

    Eject unmounted USB device in Linux (such as Kindle)

    sudo eject /dev/sdc1

    Mounting LVM volume partition

    lvm help # Available lvm commands lvscan # List all logical volumes in all volume groups pvscan # List all physical volumes lvdisplay /dev/vg1 # Display information about a logical volume vgchange -a y vg1 # Activate your volume group mount /dev/vg1/root mnt # Mount a logical volume

    Open emacs in Xterm

    emacs -nw [filename]

    Acer-wmi and wireless connections

    Make sure that wireless is set on when the module is loaded:
    modprobe acer_wmi wireless=1
    dmesg should print something like this:
    [  942.771786] acer-wmi: Acer Laptop ACPI-WMI Extras
    [  942.775138] Registered led device: acer-wmi::mail
    [  943.000081] b43-phy0: Radio hardware status changed to ENABLED
    Then just use it:
    iwconfig wlan0 essid YOUR_ESSID
    dhclient wlan0
    Alternatively you can set the wireless on after loading like this:
    echo "1" > /sys/devices/platform/acer-wmi/wireless

    Working with Logitech QuickCam for Notebooks Pro (046d:08cb)

    You need uvc-video kernel module:
    If the webcame does not work, e.g. with xawtv, easiest "solution" is to force the camera to fullspeed mode by removing ehci-hcd:
    rmmod ehci-hcd

    Show user idle time in IRC

    /WII nickki

    Configure temperature sensors

    aptitude install lm-sensors
    Then configure using:
    You can view the sensors with:

    Screen capture a frame from SimPartner video

    Capture jpeg from 20 seconds point:
    mplayer -nosound -vo jpeg -frames 1 -ss 20 input.avi -loop 1

    mencoder tips

    Fix header:
    mencoder -idx rikkinainen.avi -ovc copy -oac copy -o ehja.avi
    Compress a video file to mpeg4 (two pass):
    mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o /dev/null
    mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vpass=2 -oac copy -o output.avi
    Make video from jpeg images:
    mencoder mf://*.jpg -mf w=320:h=240:fps=10:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o filename.avi

    How to grep more than two patterns

    Use -e switch:
    iwlist wlan0 scan | grep -i -e key -e essid

    Helvetin skandit osa II - xterm skulaa

    Start xterm with: "LC_CTYPE=fi_FI xterm" command. If this works, add in the ~/.bashrc file "LC_CTYPE=fi_FI" and your skandit/ääkkoset will probably work.

    Skandit in emacs

    Add these lines in the end of ~/.emacs file:
    (prefer-coding-system 'latin-1)
    (set-keyboard-coding-system 'latin-1)
    (set-clipboard-coding-system nil)
    (set-terminal-coding-system nil)

    Comment/uncomment region in emacs

    Select start of the area with:
    Comment the area:
    Ctrl+c Ctrl+c
    Uncomment the area:
    Ctrl+u Ctrl+c Ctrl+c

    Resize your windows partition for example to install linux

    Defragment first your Windows partition in Windows.
    Then boot e.g. with Ubuntu Dekstop installation CD into Linux.
    Use gparted to resize your windows partition to desired size.
    gparted - GNOME partition editor

    Encrypted system partition at install

    Basically you need alternate installation CD of Ubuntu, e.g.:
    NOT Desktop or Server installation versions.
    1) Choose one boot partition, e.g. 1GB, which is not encrypted.
    2) Choose root and boot partition that are encrypted, e.g. 4GB and 100GB.
    3) Choose "Configure encrypted partitions".
    4) Set boot and root sections to the partitions.
    5) Write partitions to the disk.

    Make encrypted swap partition without passphrase

    Edit /etc/crypttab, add: swap /dev/disk/by-uuid/SWAPPARTITIO /dev/urandom swap
    Edit /etc/fstab, add:
    /dev/mapper/swap none swap sw 0 0
    Add finally update the init ram filesystem:
    update-initramfs -u

    Edit crontab entries of the user

    Check that they are ok:
    crontab -l

    Touch files recursively

    find /dir/to/be/touched/ -exec touch {} \;

    Mount luks partition which is in file

    losetup /dev/loop1 luksfile.dd
    cryptsetup luksOpen /dev/loop1 luksfile
    mount /dev/mapper/luksfile mnt
    When unmount, remember to unmount loop device also:
    losetup -d /dev/loop1

    Force hard disk check

    touch /forcefsck

    List symbols contained in an object file

    nm -D

    Linking order with g++

    "The traditional behavior of linkers is to search for external functions from left to right in the libraries specified on the command line. This means that a library containing the definition of a function should appear after any source files or object files which use it."
    For example: g++ test.cpp -lm -o test

    What process is occupying your tcp port

    Log in as root (in order to see all processes) and:
    fuser -n tcp 22
    fuser 22/tcp

    Check what devices and in which ports are in your network

    For example:
    nmap -v 192.168.100.*

    unrm brute-force howto

    First, unmount the file system from where you deleted the unfortunate files.
    Then install (or better, have already installed):
    aptitude install tct
    Copy all unallocated data from the disk to safety:
    unrm -f ext2fs /dev/mapper/truecrypt5 > /media/undelete.bin
    Use less or similar to find e.g. "\document" word.

    Create A4 pdf of your picture

    convert -page A4+0+0 image.XXX document.eps2
    epstopdf document.eps2

    Get all info about USB device

    udevadm info -q all -n /dev/video0

    How to set unique udev name for your USB device

    First find the device path of your device:
    udevadm info -q all -n /dev/video0 | grep "P:"
    result is e.g. "P: /devices/pci0000:00/0000:00:13.0/usb2/2-1/2-1:1.0/video4linux/video0"
    Then check the parameters of this device:
    udevadm info -a -p /devices/pci0000:00/0000:00:13.0/usb2/2-1/2-1:1.0/video4linux/video0
    Find some unique keys to identify the device from this output, e.g.:
    Next write this info to udev rule, e.g. to /etc/udev/rules.d/10-local.rules (or any file in /etc/udev/rules.d/):
    SUBSYSTEM=="video4linux", ATTRS{vendor}=="0x1002", ATTRS{device}=="0x4374", SYMLINK+="myVideo"

    Restart the udev and you should in business:
    udevadm control --reload-rules
    service udev restart

    Resolving svn conflicts

    svn resolve [path or dir]

    Undelete vfat/fat32 data

    First copy all free data to image file:
    blkls -f fat /dev/sda2 >
    Next find data from here, e.g. with foremost:
    sudo foremost -t avi -i -o /boot/backup/
    The above managed to recover 100MB data from 3GB image. Below managed to recover 700MB of data:
    magicrescue -r avi -d /boot/backup/ver3
    Including some H.264 X.264 files.
    Third thing you can try is photorec:
    Proceed -> Intel
    File Opt -> riff
    Then finally Search and Other file system
    This method managed to recover 1.45GB of data from the 3GB image, including files that were not recover by other methods.

    Before all of the above methods you REALLY SHOULD however try testdisk:
    testdisk /dev/sda
    Proceed -> Intel -> Advanced -> /dev/sda2 and then Undelete
    Find the file you want to undelete and choose "c" to copy it to safety.

    Ssh connection without password

    In computer FROM which you want to connect:
    ssh-keygen --t
    cat ~/.ssh/ | ssh -l USERNAME TARGET.SERVER.COM 'cat >> ~/.ssh/authorized_keys'

    Filemanager with video thumnails


    Use region in Latex

    ctrl+space sets start of the region and cursor location end.
    You can cut for example with ctrl+w.

    Generate timestamp in C for filename for instance

    time_t now = time(NULL);
    struct tm *ptm = localtime(&now);
    char buffer[32];
    strftime(buffer, 32, "%Y_%m_%d_%H_%M_%S", ptm);
    cout<<"time: "<<buffer<<endl;

    Changing locale settings

    Check settings:
    echo ä | hexdump -C
    00000000 e4 0a # This means ISO-8859-15 in use
    00000000 c3 a4 0a # This means that UTF-8 is in use
    Which locale to use:
    If you do NOT want that applications speak finnish to use: en_US.utf8
    It should be here the right locale (do not add manually but use locale-gen):
    Also add in the /etc/environment:
    You should probably add these in .bashrc:
    export LANG=en_US.UTF-8
    export LESSCHARSET=utf-8
    To make emacs work, add these to .emacs file:
    (setq locale-coding-system 'utf-8)
    (set-terminal-coding-system 'utf-8)
    (set-keyboard-coding-system 'utf-8)
    (set-selection-coding-system 'utf-8)
    (prefer-coding-system 'utf-8)
    Make lynx to use utf8:
    lynx -display_charset=utf8
    Make screen use utf8:
    Ctrl+: utf8 on on

    Add timestamp and ipfrom mysql columns


    mov to avi with ffmpeg

    ffmpeg -i input.MOV -g 30 -sameq -vcodec msmpeg4v2 -acodec pcm_u8 output.avi

    cr2 to jpg

    Camera white balance:
    for i in *.CR2; do ufraw-batch ${i} --wb=camera --out-type=jpeg --output=$i.jpg; done
    Works, but not so good:
    for i in *.CR2; do dcraw -c -q 0 -w -H 5 -b 8 $i | cjpeg -quality 80 > $i.jpg; echo "$i done"; done
    Gimp support (for manual tuning):
    aptitude install ufraw gimp-ufraw

    Scale/resize any pdf to A4 size

    Use acroread and print the pdf to file in A4 size, e.g.
    Now you should have test.pdf in A4 size.

    Protect a web folder with .htaccess

    Create .htaccess file like this:
    AuthUserFile /home/users/ssheikki/.htpasswd 
    AuthName "Secret area" 
    AuthType Basic 
    require user ssheikki
    Create passwd:
    htpasswd -c .htpasswd ssheikki

    CVS repository to git

    git cvsimport -a -i -k -d /home/ssheikki/cvs_repository/ -C mielipiteet opinions
    Now mielipiteet directory has git repository of opinions module.

    Make copy of remote git repository

    git remote add lakka ssh://

    Check if you have BCM43xx chipset

    lspci -vvnn | grep 14e4
    02:00.0 Network controller [0280]: Broadcom Corporation BCM4313
    802.11b/g/n Wireless LAN Controller [14e4:4727] (rev 01)
    lshw -C network
           description: Network controller
           product: BCM4313 802.11b/g/n Wireless LAN Controller
           vendor: Broadcom Corporation
    eth0: Broadcom BCM4727 802.11 Hybrid Wireless Controller

    Replace all strings inside a file

    sed -i 's/old_string/new_string/g' target_file.txt

    Run ssh commands without password prompt

    sshpass -p 'password' ssh user@server 'command'

    Encrypt/decrypt directory with openssl

    mkdir test; echo "koe">test/koe; echo "koe2">test/koe2
    tar cvzf - test | openssl des3 -salt -k secretkey | dd of=encrypted_data
    dd if=encrypted_data |openssl des3 -d -k secretkey |tar xvzf -

    Remove bash history and exit

    history -c && exit

    Monitor how many open tcp connections there is (open sockets)

    watch --interval 1 "netstat | grep tcp | wc -l"

    Get maximum number of processes you can run

    cat /proc/sys/kernel/pid_max

    Create bootable Live USB drives for a variety of Linux distributions


    Write several lines to file in bash

    cat >> filename_where_to_write.txt << EOF
    Here is text that should be appended to the file.
    Here is some more text.

    Creating and dynamically linking "shared object" libraries (.so)

    # Creating
    g++ -Wall -fPIC -c *.c
    gcc -shared -Wl,-soname, -o *.o
    # Linking
    g++ -Wall main.c -L. -lsolinktest -o main
    # Using

    Enable ssh connections remote forwarding

    Add in /etc/ssh/sshd_config, e.g. in the end:
    GatewayPorts yes

    Wireshark filter rules

    Show all traffic to/from ips 10.40.*.*
    which is http protocol
    ip.addr== and http

    Record how long program run into a file

    /usr/bin/time --verbose -o time_out.txt -a ./a.out

    Check how much real memory is used by program

    top -p
    and see column RES

    Copy symbolic links as they are

    cp -d

    Strip the first line of a file

    echo $'1\n2\n3\n4' | tail -n +2

    Make 100MB ramdisk

    mkdir -p /mnt/tmpfs
    mount -o size=100M -t tmpfs none /mnt/tmpfs

    Disable yum auto updates

    yum remove yum-autoupdate
    /sbin/service yum-autoupdate stop
    /sbin/chkconfig --del yum-autoupdate

    Check which libraries program needs

    ldd ./main
    You can define missing ones e.g. like this:
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../path_of_missing_library/ ldd ./main

    List ips that point to certain dns name


    Execute command at certain time

    echo "ls /tmp/ > /tmp/txt.txt" | at 13:30

    Convert UNIX epoch time to human readable and back

    $ date +%s -d"Tue Jul 16 14:05:05 CEST 2013"
    $ date -d @1373976305
    Tue Jul 16 14:05:05 CEST 2013

    Kill a suspended process

    [3]+  Stopped  my-program
    kill %3

    Calculate floating point numbers in Linux

    echo "scale=2;2/3" | bc

    Concanate lines in Linux

    seq 1 6 | sed ':x;N;s/\n/ /;tx'
    1 2 3 4 5 6
    seq 1 6 | sed -e :x -e 'N;s/\n/+/;tx' |bc

    Check git what has changed

    Last commited files:
    git log -1 --stat
    Changes in files:
    git log -p -1

    Rename files in linux

    There is two versions of rename:
    rename file- file2- *
    rename 's/file-/file2-/' *

    Replace string inside a file

    sed 's/originalstring/replacedstring/' filename.txt

    Get last command starting with letter x

    echo "!x"

    Measure disk IO

    vmstat -n 1
    iostat -x

    Empty file cache

    echo 3 > /proc/sys/vm/drop_caches

    Trace system calls (e.g. IO calls)

    strace -c
    strace -f -e trace=read,write

    Execute further commands only if previous fail

    rm filethatdoesnotexist.txt || echo 2
    0 || 1

    Do no execute next commands if previous ones fail

    rm filethatdoesnotexist.txt && (echo 2;echo 3)
    rm filethatdoesnotexist.txt && echo 2 && echo 3

    Set which java version maven is using

    User JAVA_HOME variable to point to the java version to be used:
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-
    mvn -version
    export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-
    mvn -version

    Compile with clang instead of gcc for more verbose debugging

    export CC=clang
    export CXX=clang++
    cmake ..

    Git: visualise and undertand a git repository

    git log --oneline --abbrev-commit --all --graph --decorate --color

    Git: add new changes to previous commit

    git commit --amend

    Git: merge with scout pattern

    git status
    git checkout -b merging_feature
    git merge new_feature
    If failed:
    git reset --hard
    git checkout master
    git branch -D merging_feature
    If success:
    git checkout master
    git merge merging_feature

    Git: merge with savepoint pattern

    git status
    git branch savepoint
    git merge new_feature
    If failed:
    git reset --hard 
    git reset --hard savepoint # OR SHA-1 hash
    git branch -d savepoint
    If success:
    git branch -d savepoint

    Git: apply set of changes to current branch

    git cherry-pick

    Git: Merge branch to current branch and destory merged branch (rewrite history)

    git rebase

    List directory contents

    tree -C

    List all filenames and sizes

    Only filenames without path:
    find . -type f -printf "%s %f\n"
    With path:
    find . -type f -printf "%s %h%f\n"

    C++ code profiling with gprof

    g++ -pg main.c -o main
    ./main # Generates gmon.out file
    gprof -p -b ./main gmon.out

    Find lines that are in a first file from the second

    for i in {1..10}; do echo $i >> first.txt;done
    for i in {8..15}; do echo $i >> second.txt;done
    grep -x -f first.txt second.txt

    Monitor traffic on remote machine with wireshark GUI

    ssh 'tshark -f "port !22" -w -' | wireshark -k -i -
    ssh tcpdump -iany -U -s0 -w - 'not port 22' | wireshark -k -i -

    svn export in git

    git archive master | tar -x -C /targetdir

    Show whole history of file in git (also renames)

    git log --follow yourfile.txt

    Grep files found with find

    grep print `find . | grep m$`

    Print nice eps figures in octave 3.6.4 etc

    set([gca; findall(gca, 'Type','text')], 'FontSize', 16);
    set([gca; findall(gca, 'Type','line')], 'linewidth', 3);
    print -depsc2 figure.eps

    How to create and use core dump

    g++ -g crasher.c
    ulimit -c unlimited
    gdb ./a.out core.23531

    Get number of file handles allowed for login session

    ulimit -Sn
    ulimit -Hn

    Detect memory leaks, uninitialise variables, and invalid pointers with valgrind

    valgrind --tool=memcheck ./a.out
    valgrind --tool=memcheck --leak-check=yes ./a.out

    Static code analysers that you might want to try C/C++

    clang++ --analyze test.cpp 
    cppcheck --enable=all test.cpp
    splint test.c

    Show files that changed between commits

    git diff --name-only HEAD~3 HEAD
    git diff --name-only origin/HEAD HEAD
    git diff origin/HEAD HEAD file.txtku

    Commit only changed files from current directory to git

    git add -u
    git commit .

    Install perl scripts from Comprehensive Perl Archive Network (CPAN)

    perl -MCPAN -e shell 
    Search programs:
    m Email::Outlook::Message
    install Email::Outlook::Message

    Package managers for different programming languages
    Perl - CPAN -
    PHP - Pear -
    Python - Pip -
    Python - EasyInstall -
    Ruby - rubygems -

    Check which version of scientic linux you are running

    grep -i 'scientific linux cern' /etc/redhat-release
    cat /etc/issue

    Start gdb with executable parameters

    gdb --args <program> <program_parameters>

    Git usage tips - best practises

    - Compare index and HEAD
      git diff -cached
    - Add files by reviewing what you add:
      git add -p
      git add --patch
    - Use atomic commits ("commit per feature")
    - Commit message <= 50 chars
    - ref~1 (previous commit), ref^1 (previous parent)
    - Hunt bugs
      git bisect start      # Start bug hunting
      git bisect bad        # This commit is broken
      git bisect good v1.0  # This commit still worked
      git bisect reset      # When bug was found (returns to intial state)
    - Hunt bugs automagic
      git bisect start HEAD v1.0
      git bisect run # or make tests
    - Undo adding of file (after git add file.txt)
      git reset file.txt
    - Undo previous commit:
      git reset -soft HEAD^ # HEAD is moved back
      git reset HEAD^       # HEAD and index moved back
      git reset -hard HEAD^ # HEAD, index and working tree moved back
    - Undo hard reset (if it was mistake)
      git reflog
      git rebase <commit hash>
    - Clean repository for backup
       git reflog expire --expire=1.minute refs/heads/master
       git fsck --unreachable      
       git prune                   
       git gc 
    - Delete and rename brach
      git branch -d
      git branch -m
    - Create branch and move into it
      git checkout -b <branch>
    - Prefer rebasing over merging branches: avoids gluttering meta-data commits
      (you should not need to use normally git cherry-pick)
    - Good workflow might look like:
      # "we are on master"
      git checkout -b newfeature
      # "make changes"
      git commit -m "New feature"
      git rebase master
      git checkout master
      git merge newfeature
      git push origin master
      # if push fails (because somebody managed to change master)
      git pull --rebase
    - List branches
      git branch
      git branch -r # remote ones
    - Meld, remove, edit, reorder commits
      git rebase --interactive
    - Store changes away temporarily
      git stash save "Described changes"
    - Repository is for source code only (no binaries, distros, etc.)

    Configure firewall with ufw

    ufw allow <port>
    ufw deny <port>
    ufw status

    Capture video from screen for certain amount of time

    recordmydesktop -x 150 -y 120 -width 700 -height 500 -fps 30 --full-shots -o output.ogv
    Check the PID:
    ps aux | grep recordmydesktop | grep -v grep
    Record 50 minutes:
    sleep 3000 && kill -INT <PID>

    Check if DNS cache is working

    Launch wireshark and use this filter:
    Try to get some domain, e.g.:
    getent hosts
    There should be just one DNS request.

    Configure caching DNS server: nscd

    yum install nscd # A Name Service Caching Daemon (nscd).
    Check if DNS cache is working - should work like a dream.
    If like nightmare, asking lots of requests every 15 seconds, do:
    rm /var/db/nscd/hosts
    service nscd restart
    If still problems, enabling debug from /etc/nscd.conf
    and checking /var/log/nscd.log should be very useful.

    Find pid of your applications

    pidof <application_name>
    pidof firefox

    List files opened by PID

    lsof -a -p 28290
    or by anybody
    lsof | wc -l
    sysctl fs.file-nr

    List content of yum package

    repoquery -l <package_name>
    repoquery -l NetworkManager-gnome

    Install driver for Broadcom BCM4313 802.11bgn Wireless Network Adapter

    Check that you have right driver:
    lspci -vvnn | grep 14e4
    Download Linux STA driver package:
    Install like this:
    If the compile fails, you might want to try:
    make API=WEXT
    sudo cp wl.ko /lib/modules/`uname -r`/kernel/drivers/net/wireless
    sudo depmod -a
    modprobe wl
    For loading the module in startup, add:
    or simply
    echo modeprobe wl >> /etc/rc.local

    Configure and enable wireless connection with Enlightenment

    sudo service NetworkManager status
    sudo service NetworkManager stop
    Add system tray to englihtenment to display nm-applet:
    1) Open "Settings" -> "Modules" configuration window.
    2) Click "Systray" and "Load".
    3) In "Shelf Contents" window, click "Systray" and "Add Gadget"
    To start it automatically:
    Setting -> Apps -> Startup Applications and enable "Network Manager" on the System tab.
    Maybe worth knowing is also:

    Running google test suite

    List available tests:
    ./unittests --gtest_list_tests
    Run specific test set:
    ./unittests --gtest_filter=T_UploadFacility.*
    Run specific test only:
    ./unittests --gtest_filter=T_UploadFacility.Callbacks

    Alternative for netcat server

    nc.traditional -v -l -p 5001
    is same as
    socat - TCP-LISTEN:5001,crlf

    Benchmark network speed

    apt-get install iperf
    Server side:
    iperf -s 
    Server listening on TCP port 5001
    TCP window size: 85.3 KByte (default)
    Client side:
    iperf -c
    Example output in server side:
    [  4] local port 5001 connected with port 57633
    [ ID] Interval       Transfer     Bandwidth
    [  4]  0.0-10.1 sec   117 MBytes  96.8 Mbits/sec
    Example output in client side:
    [  3] local port 57633 connected with port 5001
    [ ID] Interval       Transfer     Bandwidth
    [  3]  0.0-10.0 sec   117 MBytes  97.5 Mbits/sec
    You can also monitor packet losses:
    Server: iperf -s -u -i 1
    Client: iperf -c -u -b 10m
    Example output server side:
    [ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
    [  4]  0.0- 1.0 sec  11.7 MBytes  97.9 Mbits/sec   0.024 ms   70/ 8394 (0.83%)
    [  4]  1.0- 2.0 sec  11.7 MBytes  97.9 Mbits/sec   0.123 ms  182/ 8511 (2.1%)
    [  4]  2.0- 3.0 sec  11.7 MBytes  98.0 Mbits/sec   0.029 ms  202/ 8539 (2.4%)
    [  4]  0.0-10.0 sec   117 MBytes  98.0 Mbits/sec   0.215 ms 1818/85257 (2.1%)
    [  4]  0.0-10.0 sec  124 datagrams received out-of-order

    Check process related file descriptor (open file) limit

    cat /proc/<pid>/limits
    for example
    grep open /proc/3531/limits 
    Max open files            1024                 4096                 files