Rotate a PDF under Ubuntu Linux
Use the PDF toolkit:
sudo apt-get install pdftk
To rotate page 1 by 90 degrees clockwise:
pdftk in.pdf cat 1E output out.pdf # old pdftk
pdftk in.pdf cat 1east output out.pdf # new pdftk
To rotate all pages clockwise:
pdftk in.pdf cat 1-endE output out.pdf # old pdftk
pdftk in.pdf cat 1-endeast output out.pdf # new pdftk
The E
(old pdftk) or east
(new pdftk) is meaningful if you want other rotations. From the man
page:
The page rotation setting...
Fix: Tail says "no space left on device"
Linux provides a fix number of filesystem watches. If you have some greedy daemon (like dropbox) running, chances are it uses all of them, and you cannot use tail -f
any more.
To increase the number of watches, put something like
fs.inotify.max_user_watches = 32768
into /etc/sysctl.conf
. (default is 8192)
To update the setting right away, run
sudo sysctl -p /etc/sysctl.conf
afterwards.
Grep the number of occurences in a file, counting multiple hits per line
Grep prints one line per match. To return the number if matches, use the -c
switch:
grep -c "something" filename
However, if a word appears more than once in a line, it is only counted once.
To count every match, you can use sed
to force line breaks on multiple matches:
sed 's/something/something\n/g' filename | grep -c "something"
Hide your Selenium browser window with a VNC server
This is now part of geordi. Please don't follow the instructions below, if you use geordi.
Inspired by the recent headless Selenium note, I found yet another solution for the problem to hide your selenium tests away.
This has the advantages
^
- not to require a gem (so you do not force this on others)
- to allow you to take a look at the running webdriver if necessary
Simply make a script th...
How to look at hidden X screens
When you have a program running in a hidden X screen (like with Xvfb for Selenium tests) you may want to look at that hidden screen occasionally.
First, find out what X displays are currently active:
netstat -nlp | grep X11
This should give you some results like these:
unix 2 [ ACC ] STREAM LISTENING 8029600 4086/Xvfb /tmp/.X11-unix/X99
unix 2 [ ACC ] STREAM LISTENING 8616 - ...
How to type accented characters on keyboard layouts without dead keys
Ubuntu comes with keyboard layouts like "Germany Eliminate Dead Keys", which are practical for programming.
If you need to type accented characters with such a layout, make sure to configure a Compose key. You can then look up which compose combo will produce the character you need.
E.g. you can type "á" by pressing Compose, ´, a
.
Linux: Create file of a given size
Sometimes you need a file of some size (possibly for testing purposes). On Linux, you can use dd
to create one.
Let's say you want a 23 MB file called test.file
. You would then run this:
dd if=/dev/zero of=test.file bs=1048576 count=23
The block size (bs
) is set to 1 MB (1024^2 bytes) here, writing 23 such chunks makes the file 23 MB big.\
Adjust to your needs.
This linux command might also come in handy in a Ruby program. It could be used like:
mb = 23
mb_string, _error_str, _status = Open3.capture3('dd if=/dev/zero...
Dotfiles: Keep your linux configuration on github
How to enlarge a VirtualBox VDI disk file
VirtualBox does not offer anything for this task -- you need to do it yourself. It's not that hard:
Get more disk space
- Add an extra virtual hard disk to the machine with the disk size you want to achieve.
- Get a Linux live CD (like the Ubuntu live image) that offers
fdisk
,dd
andgParted
. - Boot the guest from the CD, open a terminal (on the guest, not the host!) and become root:
sudo su
-
fdisk -l
to see the disk information. \
There should be one drive with some partitions and one without any....
Show the status of a running dd copy
When you do a bitwise copy using the dd
tool you will not see any output until it completes or an error occurs.
However, you can send a command signal to the process to have it show its progress so far.
From another terminal, simply call (be root or use sudo
):
pkill -USR1 dd
This makes dd
write something like this into the terminal it is running in:
388+0 records in
387+0 records out
396288000 bytes (396 MB) copied, 24.9862s, 15.9 MB/s
You may also pass the status=progress
option to dd
like so:
dd if=... o...
CPU limit
cpulimit is a simple program which attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
Using Dropbox on Ubuntu
If you are exchanging files with a client via Dropbox you do not need to access the Web page every time you want to fetch files. Instead, you can fully integrate your Dropbox account(s) into nautilus (Gnome's file manager) with automatic synchronization.
- Get the
.deb
file for your system architecture (32 or 64 bit) from the Linux download page. - Install the downloaded package using either the Gnome integration (double-click it) or the shell, e.g.: `dpkg -i naut...
How to use Ubuntu in English, but still show German formats
If you want to have an English Ubuntu UI, but still see dates, money amounts, paper formats, etc. in German formats, you can fine-tune your /etc/default/locale
like this:
LANG="en_US.UTF-8"
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
Make sure you have both en...
Linux: Refer to all arguments of a script call
In shell scripts you can use $1
to refer to the first argument, $2
for the second, etc. If you want to refer to all arguments (e.g. when writing a bash script that takes an arbitrary amount of arguments and passes them on to another call), you may not want to do a “$1 $2 $3 $4 ...
”.
Use $@
instead, like in this script:
$ cat welcome
#!/bin/bash
echo Hello to $@
When called, the above would produce this:
$ ./welcome the world and universe
Hello to the world and universe
Note that $@
works for both sh
and `ba...
Change the timestamp of a file in Ruby
This is somewhat similar to the touch
command of Linux:
FileUtils.touch 'example.txt', :mtime => Time.now - 2.hours
If you omit the :mtime
the modification timestamp will be set to the current time:
FileUtils.touch 'example.txt'
You may also pass an array of filenames:
FileUtils.touch %w[ foo bar baz ], :mtime => Time.now - 2.hours
Non-existent files will be created.
Force Google Chrome to run in English on Linux
If you need Google Chrome to run in English, and your system locale is a non-English one, you have two options:
- Switch your system to an English locale
- Head over to
/opt/google/chrome/locales/
and remove any.pak
files except those starting with “en
”. They reappear when Chrome gets updated.
This may help you running your Selenium tests using the Chrome driver on applications that choose the language from what the browser sends as preferred language (which Chrome guesses from your system locale).
List directories ordered by size (with human-readable output)
You know there is the du
command to fetch the disk usage of a directory (“.
” in this example). By default, output is sorted by directory name, not size:
du -h --max-depth=1 .
40K ./a
2.3G ./b
3.1M ./c
500M ./d
2.8G .
To see which directories take up the most (or least) space you can order them by size like this (the -h
switch does the magic of understanding humanized size formats):
du -h --max-depth=1 . | sort -h
40K ./a
3.1M ./c
500M ./d
2.3G ./b
2.8G .
Note that you will need to...
Enable soft tabs in Vim
If you want to enforce soft tabs (spaces instead of tabstops) in Vim put this into your ~/.vimrc
(Linux) or C:\Users\<Username>\_vimrc
(Windows):
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
You can also call those commands in a running Vim instance (using ":set ...
") to switch on soft tabs temporarily.
On a side note: remember the :mkvimrc
command that saves active settings to a vimrc file.
Defining host aliases in your SSH config
You probably already manage servers you often connect to inside the ~/.ssh/config
file. What is nice: you may define alias names for hosts so that you can say something like ssh foobar-staging
.
This is especially helpful for servers whose hostnames are hard to remember or who don't have a DNS record at all (and must be accessed via their IP address).
To achieve the above, you can define something like this in your ~/.ssh/config
:
Host foobar-staging
Hostname staging.example.com
Note that SSH will only match this for `ssh f...
Move Window Buttons Back to the Right in Ubuntu 10.04 / 10.10
One of the more controversial changes in the Ubuntu 10.04 beta is the Mac OS-inspired change to have window buttons on the left side. We’ll show you how to move the buttons back to the right.
Or run this via console:
gconftool-2 --set /apps/metacity/general/button_layout \
--type string "menu:minimize,maximize,close"
Getting started with Puppet
When you simply want to get to know Puppet, follow puppetlabs’ Learning Puppet Docs. They give you a handy introduction inside a virtual machine they provide. You can watch the talk by Garrett Honeycutt 'Expanded Introduction to Puppet'.
Do not miss their cheatsheat and their [learn-puppet virtual machine](http://info.puppetl...
How to send HTTP requests using cURL
-
Reading a URL via GET:
curl http://example.com/
-
Defining any HTTP method (like POST or PUT):
curl http://example.com/users/1 -XPUT
-
Sending data with a request:
curl http://example.com/users -d"first_name=Bruce&last_name=Wayne"
If you use
-d
and do not set an HTTP request method it automatically defaults to POST. -
Performing basic authentication:
curl http://user:password@example.com/users/1
-
All together now:
curl http://user:password@example.com/users/1 -XPUT -d"screen_name=batman"
...
Installing RMagick on Ubuntu
When installing RMagick you may get an error messages like this:
Version 2.13.1:
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /home/arne/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
d...
How to send a test e-mail from shell
If you want to manually check if e-mail delivery works on a machine by sending an e-mail you can run the following:
mail -s Test someone@example.com < /dev/null
This will send an empty e-mail with "Test" as its subject to someone@example.com
.
If you want it to contain a message body, call mail -s Test someone@example.com
only; the mail
application will then read your input from stdin. Finish your message by sending EOT with Ctrl-D -- if you are asked for anything else ...