Rotate videos using HandBrake

handbrake_compRecently I recorded a video with my mobile inverted. When searching for a tool to undo the rotation I found that HandBrake can do what I wanted. HandBrake is a very popular and powerful multiplatform transcoder that gives fantastic output video and audio qualities at a smaller size if the right parameters are used. It has both GUI and CLI modes. There are many powerful switches in the CLI mode. For example to rotate a video by 90° clockwise, try the following command:

$ HandBrakeCLI -i input.mp4 -o output.mkv --preset=Custom --rotate=4

where Custom is one of the presets you saved in the GUI mode.

You can do the same from the GUI as well, add the following to Video ▸ Extra options (available only for x264 on Linux):

Custom --rotate=4

Manage your disks with Parted on Linux

diskWhile there is a GUI front-end to parted on Linux (GParted), I use cmdline parted and fdisk to handle my disks most of the time. In this article I will explain how to partition a fresh disk using parted. Straight to business with a new pen drive (operations are exactly the same as hard disk) and as root (you can also use sudo).

Once you connect the drive to Linux you have to know which is the correct device node:

# dmesg|tail -f
[16005.985619] sd 8:0:0:0: [sdb] Write Protect is off
[16005.985623] sd 8:0:0:0: [sdb] Mode Sense: 43 00 00 00
[16005.986328] sd 8:0:0:0: [sdb] No Caching mode page found
[16005.986332] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[16005.989478] sd 8:0:0:0: [sdb] No Caching mode page found
[16005.989482] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[16005.991658] sdb: unknown partition table
[16005.993343] sd 8:0:0:0: [sdb] No Caching mode page found
[16005.993357] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[16005.993360] sd 8:0:0:0: [sdb] Attached SCSI removable disk

So it’s detected as sdb. You can also use fdisk:

# fdisk -l

Disk /dev/sdb: 16.2 GB, 16219373568 bytes
64 heads, 32 sectors/track, 15468 cylinders, total 31678464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Get it ready using parted. Comments in bold:

# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) help //see what commands are supported
align-check TYPE N check partition N for TYPE(min|opt) alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted

(parted) mklabel //choose the disk partitioning scheme. msdos and gpt are common
New disk label type? //double TAB shows the options below
aix amiga bsd dvh gpt loop mac msdos pc98 sun
New disk label type? msdos

(parted) mkpart //create a new partition
Partition type? primary/extended? p
File system type? [ext2]? //double TAB for options
affs0 affs4 amufs amufs3 apfs2 ext3 freebsd-ufs hp-ufs linux-swap(old) reiserfs zfs
affs1 affs5 amufs0 amufs4 asfs ext4 hfs jfs linux-swap(v0) sun-ufs
affs2 affs6 amufs1 amufs5 btrfs fat16 hfs+ linux-swap linux-swap(v1) swsusp
affs3 affs7 amufs2 apfs1 ext2 fat32 hfsx linux-swap(new) ntfs xfs
File system type? [ext2]? ntfs
Start? 1 //start the first partition at 1 MB
End? 4000 //upto 4000 MB

(parted) mkpart
Partition type? primary/extended? p
File system type? [ext2]? ext4
Start? 4000 //we ended first partition at 4000. parted adjusts automatically! 
End? -1 //-1 means the last sector of the disk. We are using all the available space

(parted) p //check the partition details on the drive
Model: JetFlash Transcend 16GB (scsi)
Disk /dev/sdb: 16.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 1049kB 4000MB 3999MB primary ntfs
2 4000MB 16.2GB 12.2GB primary

(parted) quit //all done!
Information: You may need to update /etc/fstab.

Now you have a disk with one ntfs and one ext4 partition. Well! Not yet! Parted just set the information about the filesystem types (ntfs and ext4) in the MBR. You have to format the partitions to start using them.

# mkntfs -fc 4096 /dev/sdb1 //ntfs filesystem, cluster size 4KB (common for NTFS)
# mkfs.ext4 /dev/sdb2 //ext4 filesystem

That’s it! The pen drive is ready with a 4GB NTFS partition and a 12.2GB EXT4 partition. And do you know that (specifically in case of a pen drive) though both of them will be automatically detected on any Linux distro, Windows 7 will only find the first NTFS partition. Even reformatting won’t help. The reason is that Windows 7 can detect only one partition on pen drives and thinks that’s the size of the pen drive as well.

Parted is very powerful and supports many more operations. Check out man parted.

Profile your programs with Callgrind

valgrind_compThere is a limit to how much you can optimize large pieces of code (like frameworks) through manual code analysis. While finding redundant loops, optimizing algorithms, using bitwise operators are relatively easier, it is almost impossible to detect which parts actually take up the maximum CPU time through observation. Callgrind can do that for you. While there are many other tools available, Callgrind is my favourite because it has minimum external dependencies, does not need a GUI (though an optional GUI is available) and it is very easy to run without modifying your existing code. As it is a tool that comes with the popular memory leak-checker Valgrind, it supports the same programming languages like C, C++, Java, Perl, Ptython, Assembly and many more.

I will show how to create a portable Valgrind package which you can use anywhere as long as the platform architecture matches your compilation. Here are the simple steps to test-drive Callgrind on one of your programs:

  • Download the source code from here. Available in repository by default on many distros but we want to make it portable.
  • Extract and compile Valgrind using:
    $ ./configure --prefix=/target/directory/for/package/creation/valgrind
    $ make
  • Once the compilation is over, you have Valgrind ready at
  • Export the path to the Valgrind binaries
    $ export PATH=/target/directory/for/package/creation/valgrind/bin:$PATH
  • Run your program with Callgrind (just as you normally do) to profile it:
    $ valgrind --tool=callgrind ./myprogram option1 option2
  • Check the PID of the process using:
    $ ps ax|grep valgrind
  • The profiler output file will be generated in the current directory. The name should be callgrind.out.PID (the same PID from the previous step).
  • To make it understandable and sort the functions in descending order by CPU usage time, run:
    $ callgrind_annotate callgrind.out.PID //callgrind_annotate needs Perl
  • By default callgrind_annotate prints everything in the terminal. Redirect everything to a file if you want to check it later:
    $ callgrind_annotate callgrind.out.PID > callgrind.profile

That’s simple enough! Now you have a portable Callgrind to profile your programs with.

Another heap profiler: Heaptrack

script & ttyrec: record full terminal sessions

terminalIf you want a typescript record of everything that shows up on a terminal session, script & scriptreplay combo is the exact utility you are looking for. A common use is that you can record every activity during a terminal session and the replay it later. Here’s an example:

Start recording with time information in timefile and activity record in recordfile:

$ script -ttimefile recordfile

When invoked, script starts running in the background. Everything you do from here gets recorded. To finish recording press ^D.

To reply the session, use scriptreplay:

$ scriptreplay -ttimefile recordfile

Try it yourself. Amazing, isn’t it?

This can also be done using the more advanced utilities ttyrec and ttyplay. Usage is almost similar but ttyrec does not need any extra file to record times.

Lighttpd: quickly set up a lightweight server

lighttpd_compThere are many reasons you may want to set up a small server of yours and shares files with friend and family. There are many solutions as well. But most of them are robust, huge in bulk (for example, Apache) and need professional configuration. Try Lighttpd. It is literally feather-light, has multiple mods like HTTP, webdav, magnet etc.

To install on Ubuntu, run:

$ sudo apt-get install lighttpd

Here’s a quick configuration guide for starters.

If not sure, how one can access your server over the internet, run:
# curl

or check it from A remote user can now browse your server with the IP you see.

Webpage: Lighttpd

Fossil: your local version control system

fossil_compWe keep changing documents and files and it may not be possible to track all the changes or go back to a previous state after a few days. That’s where a revision control system comes handy. While there are many cloud based solutions it is difficult to find something which runs locally and yet not too heavy. Enter Fossil – multiplatform, damn light (the Linux package is less than 1MB in size!!!) and lots of functionality and options for customization along with a web interface. You can change the settings to view diffs with your favourite diff viewer. Fossil is written in C. The official documentation is extensive. Here’s a quick guide to kickstart with Fossil:

$ mkdir /opt/myrepo //your main repository location
$ cd /opt/myrepo
$ fossil init localrepo //create a repository localrepo
$ fossil set editor vim //let vim be your editor for changelogs
$ mkdir ~/fossil_files //we'll check out here
$ cd ~/fossil_files
$ fossil open /opt/myrepo/localrepo
$ mkdir root
$ touch root/firstfile //your first file, add something in it
$ fossil commit //you just added something in your repo
$ fossil ui /opt/myrepo/localrepo //the web interface to browse repos, branches, files...

Click on the Files tab and now you can browse your newly created repository, view diffs, changelogs and everything. How cool is that?

To install Fossil on Ubuntu:

$ sudo apt-get install fossil

Navigate through the documentation to know more about Fossil. You’ll be surprised what you can do with it.

Chisel is a service offering hosting for unlimited Fossil repositories.

Webpage: Fossil

rTorrent: download torrents the geek's way

transfer_compWhen it comes to downloading torrents and magnets, I normally stick to qBittorrent on my laptop. It is easy to use, fast, smooth and light. But when you are connected to a remote machine through a terminal the situation changes abruptly. You don’t have any X support (but maybe your server is connected to the internet over a 1GBPS line waiting to be utilized). You get your hands dirty with rTorrent. Written in C++, exceptionally light, incredibly fast and running on a thin library, rTorrent is bound to amaze you once you get hold of the basic usage. It has all the essential functionality of a powerful torrent (and magnet) client.

To install rTorrent on Ubuntu:

$ sudo apt-get install rtorrent

rtorrent is highly configurable. You’ll find some useful links explaining all the configuration options towards the end of this article. For a quick start, here’s a sample configuration file. Note that you need to create the download directory (first line) and the ~/.session directory.

directory = /home/user/Downloads/torrents/
min_peers = 10
max_peers = 20

min_peers_seed = 1
max_peers_seed = 1

max_uploads = 1
max_uploads_global = 1
max_downloads_global = 3

download_rate = 0
upload_rate = 1
dht = auto
dht_port = 6881
peer_exchange = true

Some useful tips for navigation: while searching for a file, <Tab> completes the directories. And you can open a torrent file directly using

$ rtorrent mytorrent.torrent OR URL
//note: URL works for torrent only

You can close the terminal and keep rTorrent running in the background. Run:

$ dtach -A /tmp/rtorsocket -z rtorrent

To resume, run:

$ dtach -a /tmp/mytorrent.torrent

Remember not to close the terminal with <Ctrl-d>. Either close it by clicking the close button or use <Ctrl-\>. More methods to detach console processes and keep them running in the background here.

rTorrent can also download torrents if you provide the direct URL to rTorrent as a parameter while starting it.

Here are some articles explaining navigation, configuration etc. at a very granular level:

Webpage: rTorrent

cutmp3: quickly split mp3 on Linux

musicIf you want to cut out your favourite part of music as a ringtone from an mp3 file quickly, cutmp3 will come real handy on Linux. It’s a cmdline utility and available in synaptic on Ubuntu. The usage is simple:

$ cutmp3 -i input.mp3 -a mm:ss -b mm:ss -O output.mp3
//-a and -b stand for start and end in mins:secs

You can also adjust precision till fraction of a second like -a 3:20.5

Webpage: cutmp3

copy & move on Linux with progress bar

terminalIf you feel a bit lost while copying or moving huge files on Linux from the terminal wondering where it stands, Advanced Copy is the right tool for you. Installation and usage details are explained very well in the home page. The author advices to compile it on your system instead of using the pre-compiled binaries. The usage is as easy as adding aliases to your .bashrc file to cp -g and mv -g and running cp or mv as you do:

alias cp='cp -g'
alias mv='mv -g'

Another advanced copy utility is gcp. Available in synaptic.

Webpage: Advanced Copy (site down?) The patch for coreutils (which includes cp and mv) is still available here.

Canto: console based Linux RSS/news feed reader


In a past post I wrote about Feedly as an alternative to Google Reader. It’s definitely good but practically speaking I just love to skim through the list of feeds and open only the ones those I think would be interesting. I found exactly what I wanted – Canto. If you are thinking it’s primitive, check out the features:

  • Open any feed anytme in the browser of your choice
  • Unicode support
  • Supports both RSS, ATOM and RDF feeds.
  • Import/export feeds in OPML format
  • Theming through configuration
  • As will most Linux utilities, it is extremely flexible and can be configured to your liking
  • Very very lightweight and fast as it just downloads the feed information and no images or the full text of the news
  • For a distraction free reading, make you console fullscreen (F11) and try it out
  • Available in synaptic on Ubuntu

To install canto on Ubuntu, run:

$ sudo apt-get install canto


  • For help, run canto -h or man canto or press h when canto is open.


All your configuration goes into ~/.canto/ file. Download mine from here. I have added:

  • some feeds
  • a filter not to show read articles
  • google-chrome to open the links
    you can choose to use elinks but 1. the learning curve might be steep and 2. if you want to read the full news, why not open it in the default browser?

Basic navigation

  • To execute canto, run
    $ canto //run canto
    $ canto -a //just refresh the feeds
    $ canto -u //update feeds & open canto, you can alias this in ~/.bashrc
  • Up and Down keys navigate through the feed list.
  • Use Left and Right to mark unread and read from feed list without opening.
    Use r to mark all stories in a feed/group as read. R marks everything as read.
  • Press f in feed list to search and highlight matching feeds.
  • Use Space to open details of a feed in a new frame (feed frame) and Space again to go back to feed list.
    To open directly in the browser bring the cursor to the feed and press g.
  • When within a feed frame, type g 0 (then Enter) to open it in browser. 0 is the index to the link.
    Similarly you can open other links using g n, where n is the link number in [] shown beside the link.
  • Press n and p to jump to next and previous feed from the feed frame.
  • Press l (small L) in the feed frame to expand all the links in the feed.
  • Press Ctrl-R to refresh all feeds.
  • To quit press q in the default feed list page.

If you are not sure where to start, start with adding my feed:

Webpage: Canto

Similar software