These are some random tips, collected for personal usage, on the usage of a few tools useful in a Linux environment.
Whenever you log into your SSH account on some host (e.g. your webhosting provider) you'll be prompted for and have to enter a password. Although this is important for the security of your account, it might be annoying at some point. Fortunately, there is a way to automate the authorization. To do this create locally (i.e. on the client) a pair of keys consisting of a private and a public key. As the name implies the public key doesn't need to be kept secure. It's the one we will transfer to the server. But make sure that the private key is kept secret and is not available for anyone else, as this would have the same effect as telling the password to your account.
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/armin/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/armin/.ssh/id_rsa. Your public key has been saved in /home/armin/.ssh/id_rsa.pub. The key fingerprint is: [Some numbers] armin@armin-laptop
Transfer the public part of this key to the server.
$ ssh-copy-id -i ~/.ssh/id_rsa.pub username@server
You should now be able to log into your server without typing a password. More details and a further discussion on more secure variants can be found e.g. at http://www.debian-administration.org/articles/152.
OpenSSH and SSH
The above implies that both the workstation and the server are using OpenSSH. However, you can still setup passwordless logins when e.g. the server uses SSH. You can find out which versions are in use by issuing
$ ssh -V ssh: SSH Secure Shell 126.96.36.199 (non-commercial version) on i686-pc-linux-gnu
In this case we get to know that the machine does not use OpenSSH but SSH instead.
First we have to convert our public key id_rsa.pub so that it will be readable for SSH as well. This is done by
$ ssh-keygen -f id_rsa.pub -e >> id_rsa_openssh.pub
Now, we transfer this key to the server and configure the server so it will use it.
$ scp id_rsa_openssh.pub username@server:~/.ssh2 $ ssh username@server 'echo "Key id_rsa_openssh.pub" >> \ > .ssh2/authorization'
Work with PDF & PS
Convert PDF to PS
To convert from
ps you can use
$ pdftops file.pdf
There is a similar tool named
pdf2ps which internally uses
gs but it doesn't produce as good results for me.
Put several pages on a page
mpage allows one to merge
$ mpage -2 file.ps > new.ps
Alternatively, you can use
$ psnup -2 file.ps new.ps
Both tools can be used to put more than two pages on a single page (if you got good eyes).
Convert PS to an image
pstoimg can convert
ps files to image files like
$ pstoimg -type png -crop a -transparent file.eps
This way you get a nicely cropped (
-crop a) and transparent
Merge several files
To combine several
$ pdftk file1.pdf file2.pdf cat output combined.pdf
Note to myself: Did I try
Lately, I wanted to print a 4-page document on a single paper that I would fold like a card. For this I needed to print pages 4 and 1 on the front, and pages 2 and 3 on the back.
$ pdftk doc.pdf cat 4 1 2 3 output sorted.pdf $ pdftops sorted.pdf $ psnup -2 sorted.ps print2.ps $ ps2pdf print2.ps
Scale A4 to A5
First convert to
ps, then use
$ psresize -Pa4 -pa5 doc-a4.ps doc-a5.ps
Unfortunately, for me this results in A4 sized pages that contain the actual content in A5 size. To get A5 sized pages as well, I printed the document to a
To delete the first page from a
$ pdftk input.pdf cat 2-end output output.pdf
Play with djvu
To delete the first page from a
$ djvm -d ebook.djvu 1
Use your computer as an alarm
To have some command being executed at a given time you can use the standard tool
sleep is great for having something done after a certain amount of time. The following commands show for instance how to have
amarok start playing at 6:30 in the morning, or how to have it start playing in 45 minutes.
$ echo "dcop --user armin amarok player play" | at 6:30AM $ sleep 45m && amarok --play
Convert WMA to MP3
$ mplayer file.wma -vo null -vc dummy \ > -ao pcm:waveheader:file=temp.wav
This command will produce a (temporary) wave file that you can encode to mp3 for instance using
lame. While converting it might make sense to use the option
-af resample=44100. For me, however, this produces an error.
Split MP3 files
Suppose you have a music file that actually contains two songs seperated by a longer silence. You can split it into its two parts using
mp3splt (which, of course, is much more powerful than this simple example requires).
$ mp3splt -s -p nt=2,rm long.mp3
Save an internet stream
Suppose you found an internet stream of the form rtsp://*.rm that you want to save on your harddisc. With
mplayer this can be done as follows.
$ mplayer -dumpstream rtsp://*.rmIf you are only interested in audio or video you might want to take a look at the options
By the way, if trying to play a
*.ram video stream with
mplayer gives you an error like
Win32 LoadLibrary failed to load: avisynth.dll, /usr/lib/win32/avisynth.dll this usually is no problem with codecs but is because you're dealing with a playlist instead of a real video file. Try instead:
$ mplayer -playlist file.ram
Remove noise from audio
To remove noise from bad-quality audio/video files you can try to use the concept of filters in
mplayer. Ideally such filters should be able to do even greater things like producing karaoke versions of your (music) files
$ mplayer -af karaoke music.mp3but don't expect that to work. The filters
sinesuppressare supposed to remove noise but again didn't really improve my listening experience. Since the most annoying noise was kind of a constant deep crumbling, the most effective way I came up with was to use the
equalizerfilter to change the volume of certain frequency ranges.
$ mplayer -af equalizer=-12:-12:-12:-6:3:6:3:0:-12:-12 video.movThis definitely will have to be adapted to the specific movie file but the idea here is that human speech (my video was an online lecture) mainly covers the frequency range from 500Hz to 2kHz (which the 5-7th numbers refer to). Of course, you can use any player like
kaffeinethat comes with an equalizer and play with these values.
Adjust hard drive options
If I try to have my hard drive "enter the low power consumption standby mode" (see manpage of
hdparm) it immediately wakes up again.
$ sudo hdparm -C /dev/hda /dev/hda: drive state is: active/idle $ sudo hdparm -y /dev/hda /dev/hda: issuing standby command
My previous configuration and test results.
$ sudo hdparm /dev/hda /dev/hda: multcount = 0 (off) IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 1 (on) keepsettings = 0 (off) readonly = 0 (off) readahead = 256 (on) geometry = 19457/255/63, sectors = 312581808, start = 0 $ sudo hdparm -tT /dev/hda /dev/hda: Timing cached reads: 696 MB in 2.00 seconds = 348.15 MB/sec Timing buffered disk reads: 58 MB in 3.04 seconds = 19.08 MB/sec
My new hard drive is getting pretty hot while seemingly doing nothing. So I looked for ways to keep it cooler.
$ sudo hdparm -M 128 /dev/hda /dev/hda: setting acoustic management to 128 acoustic = 0 (128=quiet ... 254=fast)
Changing my settings.
(Internet) Connection sharing
Suppose, you have one computer connected to the internet (the gateway) and another one (the client) which you want to have internet connection as well. All you have to do on the client side is to add the gateway option to its network interface. The corresponding entry in /etc/network/interfaces may for instance look like
On the gateway, something like the following needs to be configured to enable forwarding.
# echo "1" > /proc/sys/net/ipv4/ip_forward # iptables -t nat -A POSTROUTING -j MASQUERADE
However, the above setup is quite insecure since any computer connected to the gateway could use it for internet access as well. Slightly more specific (see the manpage of
# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 0/0 -j MASQUERADE
Every file or directory may have properties which may be viewed, read and set as follows.
$ svn proplist kiolocate_screenshot.png $ svn propget svn:mime-type kiolocate_screenshot.png $ svn propset svn:mime-type "image/png" kiolocate_screenshot*.png
Properties starting with
svn: have special roles. For instance
svn:executable is used to mark a file as binary while the property
svn:ignore is used for the same purpose as the .cvsignore files for
CVS. It may be comfortably edited with
$ svn propedit svn:ignore .
To set certain properties automatically for particular files you can edit ~/.subversion
The python script
svnshell allows you to browse the repository using the usual
$ svnshell /data/svn
When backing up a directory which also contains files under version control it is useful to ignore the hidden copies in the .svn subdirectories. This can be done for instance with
tar using the
$ tar --exclude=".svn" -czf backup.tar.gz files