Here I collect all useful tricks & commands that I have discovered for linux. In principle I put together this collection in order to not forget any of it. However, I also hope that they are may be useful for everybody else as well.
Contents
1. Command line magic
1.1. Encode all wav files in the current directory to mp3s
you@yourbox:~$ for i in *.wav; do lame -m s -b 256 "$i" "`basename "$i" .wav`".mp3; done
1.2. Laptop Mode
In order to check whether laptop mode is currently active on your box type:
you@yourbox:~$ cat /proc/sys/vm/laptop_mode
If it returns a nonzero value, then laptop mode is enabled, if it says 0, then it isn't.
1.3. Usage history of commands
Show how often you use programs on the command line:
you@yourbox:~$ history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head -n 12
1.4. Debian: lock of apt cache
To unlock the apt cache (e.g. after package manager has crashed):
you@yourbox:~$ sudo lsof | grep /var/lib/dpkg/lock && sudo dpkg --configure -a
1.5. Join multiple pdf files
You can join multiple pdf files into one file by means of ghostscript (gs).
you@yourbox:~$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=all.pdf first.pdf second.pdf ...
1.6. Shrink size of pdf files
You can shrink the file size of pdf files with ghostscript (gs).
you@yourbox:~$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
1.7. Create EPS file from PDF
If you want to create an encapsulated postscript file from an existing pdf you can use the pdftops command:
you@yourbox:~$ pdftops -eps file.pdf file.eps
1.8. Mount/Unmount CD/DVD-ROM-ISO-Image without burning
If you want to mount you need to use the following command
you@yourbox:~$ sudo mount cdrom.iso /media/iso/ -t iso9660 -o loop
where you have to make the directory /media/iso first, and cdrom.iso should be replaced by the path to your ISO-image.
To unmount type:
you@yourbox:~$ sudo umount /media/iso
In some cases it might be necessary to load the kernel's loop module first before you can mount:
you@yourbox:~$ sudo modprobe loop
1.9. Unmount busy device
If you get the following message when trying to unmount a device:
you@yourbox:~$ umount /media/disk/ umount: /media/disk: device is busy umount: /media/disk: device is busy
you can use the fuser command to find out which process was keeping the device busy:
you@yourbox:~$ fuser -m /dev/sdc1 /dev/sdc1: 2770 you@yourbox:~$ # ps auxw|grep 2770 you 2770 0.0 0.1 4908 2080 pts/3 Ss+ 09:33 0:00 /bin/bash
After killing that process you can unmount like usual with umount.
2. Network tricks
2.1. Find IP-Address
To save the IP-Address of network device etho in the variable IP execute the following line:
you@yourbox:~$ IP=`ifconfig eth0 | grep 'inet Adresse:' | cut -d: -f2 | awk '{print $1}'`
2.2. Start VNC Server on remote host
To start a VNC server on a host to which you have ssh access and which already has an xsession running (with your user), you can type after havin logged onto the remote host:
you@yourbox:~$ x11vnc -display :0 -auth ~/.Xauthority -rfbauth .vnc/passwd
This will also produce further output that will show you how to actually connect to the running VNC server (port and so on).


