Skip to main content

Bash: useful shortcuts


  • Ctrl + A: moves cursor to beginning of line of text.
  • Ctrl + E: moves cursor to end of line of text.
  • Ctrl + L: formfeed (clear the screen terminal).

Use webcam

Add yourself to the video group:

# gpasswd -a <user> video

To use it with mplayer type the following command:

$ mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 15

Multiple screens

So, I have a laptop with a 1920*1080 screen and I want to connect it with a 1680*1050 LCD monitor through VGA.

First make sure xorg-xrandr is installed:

# pacman -S xorg-xrandr

Connect the monitor and run:

$ xrandr -q

Note the names of the two outputs, then run:

$ xrandr --output LVDS1 --pos 0x0 --mode 1920x1080 --output VGA1 --mode 1680x1050 --left-of LVDS1

Arduino Uno installation

First install the arduino package from AUR:

$ yaourt -S arduino

Add yourself to the uucp group:

# gpasswd -a <user> uucp

Logout and login again.

Connect your arduino to your computer and lauch:

$ ls /dev/ttyUSB* /dev/ttyACM*

Note the serial port of the board.

Launch the arduino program, close it, then modify ~/.arduino/preferences.txt.

Change the line serial.port=COM1 with something like this:


Lauch again the arduino program.

If you can't upload your sketch (and get the following error: Serial port '/dev/ttyACM0' not found. Did you select the right one from the Tools > Serial Port menu?), this may be because you don't have write permissions on /run/lock/ directory.

The following trick should resolve the problem:

# chmod 777 /run/lock
# cp /usr/lib/tmpfiles.d/legacy.conf /etc/tmpfiles.d/
# chmod 777 /etc/tmpfiles.d/legacy.conf

Vim: export document to PDF

If you want your syntax highlight to be exported, don't forget to activate it with:

:syntax on

Now print your document to PostScript:

:hardcopy >

Exit Vim and use ps2pdf to convert to mydocument.pdf.

$ ps2pdf

ConnectBot: Authenticate with a SSH key

First, make sure openssh-server is installed on the machine you want to connect

Generate the key

Launch ConnectBot, hit the Menu key and select Manage Pubkeys. Hit Menu → Generate.

Give your key a nickname.

Then choose encryption type. Default RSA 1024 bits should be good enough.

You now have the choice to set a password or not. You can leave it blank, but you have to know that a SSH key without password is like a bank card without PIN code; if anyone gains access to your phone or at least to your private key, he would be able to connect to every server where your public key is installed.

Check Load key on start if you want.

Press Generate and move your finger around the box to gather randomness.

Add your key on the server

Your key is now created. Long press on its name and choose Copy public key. Log in to the server (with your password) and type the following command:

$ echo "your public key" >> .ssh/authorized_keys

To paste your key using ConnectBot, tap on Menu → Paste. Don't forget the quotes.

Optimize SSD Performance

Enable TRIM

Warning: the following tip only works for Linux kernel version 2.6.33 or above, and not all filesystems are supported (as of version 3.7, ext4, btrfs, JFS and XFS support it).

Add the discard option in /etc/fstab.


/dev/sda1  /       ext4   defaults,noatime,discard   0  1
/dev/sda2  /home   ext4   defaults,noatime,discard   0  2

Firefox: add "magnet:" protocol support

Type about:config in your address bar.

Right-click → New → Boolean → Name: network.protocol-handler.expose.magnet → Value → false.

Next time you use the magnet protocol, it will give you the "associate application" box.

Point it to the magnet2torrent script below if you want to associate it with rtorrent.

rtorrent: handling "magnet:" URIs via a bash script

Create a magnet2torrent script with the following code:

#! /bin/bash

# Convert a magnet URI into a .torrent file
# Run the script with:
# (Don't forget the quotes aroud MAGNET_URI)

cd ~/watch || exit    # set your watch directory here
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit
if [[ "$1" =~ dn=([^&/]+) ]];then
echo "d10:magnet-uri${#1}:${1}e" > "meta-$filename.torrent"

Make the script executable:

$ chmod a+x magnet2torrent

Run the script with a magnet URI (after adding it to your $PATH variable):

$ magnet2torrent "MAGNET_URI"