The two clipboards in Linux

If you have come to Linux from Windows or Mac, you might have observed some strange behavior when copying or pasting content. This confusing behavior is caused because there are usually two clipboards in Linux.

X clipboard

The X window system has its own clipboard. It is also known as a cutbuffer. Any text or content you mark by highlighting with the mouse cursor is automatically copied to this clipboard. This is known as the PRIMARY selection or X Window selection or just selection in X jargon. When you middle-click the mouse cursor at the destination location, this copied content is pasted there.

Window manager clipboard

In addition to the X clipboard, your window manager or desktop environment (like KDE or GNOME) typically maintains its own clipboard. It might even have a clipboard manager which can maintain a historical buffer of content copied to the clipboard.

Typically, text or content is copied to this clipboard when you highlight it and use the keyboard shortcut Ctrl+C or right-click with mouse and choose Copy. Content from this clipboard is pasted when you use the keyboard shortcut Ctrl+V or right-click with mouse and choose Paste.

Syncing clipboards

Typically, the window manager or its clipboard manager will have an option that allows you to sync this clipboard with the X window selection clipboard. That is, content copied in either clipboard appears in the other ready for pasting.


EmojiOne Picker


I can finally stop complaining about the absence of a emoji picker for Linux. Now there is the EmojiOne Picker! It is a simple picker application based on the awesome emoji set of EmojiOne.

  • Installing from PPA is the easiest way to get it:
$ sudo add-apt-repository ppa:ys/emojione-picker
$ sudo apt update
$ sudo apt install emojione-picker
  • To use just type EmojiOne Picker at the Dash. Note that it takes a few seconds to load and finally settles down in the system tray area with a smiley face. Right-click on it to get the fully detailed list of emoji. Click on any one and it will be copied to your clipboard for easy pasting into any app or website.

  • In Settings, I like to choose the Low end computer mode which reduces the number of emoji and thus makes loading and usage of this app faster.

  • You can also right-click and choose Search to filter emoji by typing a word describing it. This is useful to find obscure emoji.

Tried with: EmojiOne Picker 0.1 and Ubuntu 16.04

Primesense on Linux

My Primesense RD1.09 camera that causes many troubles
My Primesense RD1.09 camera that causes many troubles

I have a Primesense RD1.09 camera that works without any problem under Windows using OpenNI Under Linux though, it is a world of pain!


After a lot of debugging, I have discovered that most of the problems arise if you have a computer which has USB 3.0 controllers or hubs. It does not matter if you plug in the Primesense into a USB 3.0 or USB 2.0 port. Just the existence of USB 3.0 on your computer means that the Linux kernel behaves differently.

After endless hours of plugging and unplugging into USB ports and poring over the errors in /var/log/syslog and the behavior of lsusb on 3 different computers, I believe it is the USB subsystem of Linux that is causing the problem. Linux kernel uses the XHCI module and on computers which have USB 3.0 controllers, it seems to be causing problems. For an excellent example see this scanner problem.

Additionally, if you have played around with different versions of OpenNI, that can also add another layer of bugs. Make sure you apt-get remove --purge when you remove OpenNI 1.x. Also make sure you manually remove the files installed by OpenNI 2.x (which does not have an uninstaller).


Check if you see of these symptoms when using Primesense in Linux:

  • You plug in Primesense and type lsusb. It should enumerate the USB devices in a second. If it takes longer, you have a computer with USB 3.0 ports and the buggy Linux kernel USB modules are having trouble with it.

  • Primesense is detected in lsusb and it appears as ASUS. But, running any sample viewer program returns in error.

  • Primesense is detected only half the times it is plugged in.

  • When the camera is detected, I run a program to read depth and color streams. Half the time, the color stream does not provide any frames!

  • Even when both depth and color frames are provided, the color frames have lower FPS and even freeze sometimes!


Both of these solutions worked for me:

  • On computer with USB 3.0, go to BIOS setup and disable Intel xHCI and EHCI. If your BIOS does not have these options, you are out of luck! 😦

  • Switch to an older computer which has only USB 2.0 controllers and ports.

Primesense worked flawlessly with the OpenNI 1.x packages (from Ubuntu) on the computers after I tried the above solutions! 🙂

How to use performance analysis tools of Linux kernel

The performance counters available in modern processors can be easily accessed through the Linux kernel to analyze the performance of your programs. For example, you can find out how many branch misses occurred when your program executed.

  • We first install the performance analysis tools for our specific Linux kernel version:
$ sudo apt install linux-tools-(uname -r) linux-tools-common
  • perf is the main command that we use for analysis.

  • List the performance counters and events that you can measure:

$ perf list

List of pre-defined events (to be used in -e):
  cpu-cycles OR cycles                               [Hardware event]
  instructions                                       [Hardware event]
  cache-references                                   [Hardware event]
  cache-misses                                       [Hardware event]
  branch-instructions OR branches                    [Hardware event]
  branch-misses                                      [Hardware event]
  bus-cycles                                         [Hardware event]
  ref-cycles                                         [Hardware event]

  cpu-clock                                          [Software event]
  task-clock                                         [Software event]
  page-faults OR faults                              [Software event]
  context-switches OR cs                             [Software event]
  cpu-migrations OR migrations                       [Software event]
  minor-faults                                       [Software event]
  major-faults                                       [Software event]
  alignment-faults                                   [Software event]
  emulation-faults                                   [Software event]
  dummy                                              [Software event]

  L1-dcache-loads                                    [Hardware cache event]
  L1-dcache-load-misses                              [Hardware cache event]
  L1-dcache-stores                                   [Hardware cache event]
  L1-dcache-store-misses                             [Hardware cache event]
  L1-dcache-prefetch-misses                          [Hardware cache event]
  L1-icache-load-misses                              [Hardware cache event]
  LLC-loads                                          [Hardware cache event]
  LLC-stores                                         [Hardware cache event]
  LLC-prefetches                                     [Hardware cache event]
  dTLB-loads                                         [Hardware cache event]
  dTLB-load-misses                                   [Hardware cache event]
  dTLB-stores                                        [Hardware cache event]
  dTLB-store-misses                                  [Hardware cache event]
  iTLB-loads                                         [Hardware cache event]
  iTLB-load-misses                                   [Hardware cache event]
  branch-loads                                       [Hardware cache event]
  branch-load-misses                                 [Hardware cache event]

  branch-instructions OR cpu/branch-instructions/    [Kernel PMU event]
  branch-misses OR cpu/branch-misses/                [Kernel PMU event]
  bus-cycles OR cpu/bus-cycles/                      [Kernel PMU event]
  cache-misses OR cpu/cache-misses/                  [Kernel PMU event]
  cache-references OR cpu/cache-references/          [Kernel PMU event]
  cpu-cycles OR cpu/cpu-cycles/                      [Kernel PMU event]
  cycles-ct OR cpu/cycles-ct/                        [Kernel PMU event]
  cycles-t OR cpu/cycles-t/                          [Kernel PMU event]
  el-abort OR cpu/el-abort/                          [Kernel PMU event]
  el-capacity OR cpu/el-capacity/                    [Kernel PMU event]
  el-commit OR cpu/el-commit/                        [Kernel PMU event]
  el-conflict OR cpu/el-conflict/                    [Kernel PMU event]
  el-start OR cpu/el-start/                          [Kernel PMU event]
  instructions OR cpu/instructions/                  [Kernel PMU event]
  mem-loads OR cpu/mem-loads/                        [Kernel PMU event]
  mem-stores OR cpu/mem-stores/                      [Kernel PMU event]
  tx-abort OR cpu/tx-abort/                          [Kernel PMU event]
  tx-capacity OR cpu/tx-capacity/                    [Kernel PMU event]
  tx-commit OR cpu/tx-commit/                        [Kernel PMU event]
  tx-conflict OR cpu/tx-conflict/                    [Kernel PMU event]
  tx-start OR cpu/tx-start/                          [Kernel PMU event]

  rNNN                                               [Raw hardware event descriptor]
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]
   (see 'man perf-list' on how to encode it)

  mem:<addr>[:access]                                [Hardware breakpoint]

  [ Tracepoints not available: Permission denied ]

We can see that a lot of counters and events are available for measurement. The tracepoints can be listed if the command is run as sudo.

  • We can query any of the above listed events. For example, to find out the number of branch misses in a program foo by repeatedly running the program 10 times:
$ perf stat -r 10 -e branch-misses ./foo

 Performance counter stats for './foo' (10 runs):

            42,683 branch-misses                                                 ( +-  0.55% )

       0.001782436 seconds time elapsed                                          ( +- 12.91% )

All values are the average of 10 executions, since that is what we specified.

  • To print out other stats, just append with a comma. For example, to get both branch misses and memory stores:
$ perf stat -r 10 -e branch-misses,mem-stores ./foo

 Performance counter stats for './foo' (10 runs):

            42,603 cpu/branch-misses/                                            ( +-  0.23% )
           972,221 cpu/mem-stores/                                               ( +-  0.05% )

       0.001748714 seconds time elapsed                                          ( +-  0.39% )

Tried with: Intel i7-4790, Linux 3.13.0-52-generic and Ubuntu 14.04

How to remove old Linux kernels


Ubuntu updates Linux kernels almost every month. If you regularly update Ubuntu, you will end up with a lot of old Linux kernels.

A Linux kernel in Ubuntu is installed as four packages. They are listed here for kernel 3.13.0-43: linux-headers-3.13.0-43, linux-headers-3.13.0-43-generic, linux-image-3.13.0-43-generic and linux-image-extra-3.13.0-43-generic.

You can of course look up the latest kernel version using uname -r and then proceed to remove all the rest of the Linux kernel packages manually.

A great alternative is to use the purge-old-kernels tool. This removes all but the latest 2 kernels. Strangely, it is shipped along with the Byobu package, so you will need to install that to use it:

$ sudo apt install byobu
$ sudo purge-old-kernels

Another alternative that I like is to use Ubuntu Tweak tool. It can be installed easily, as described here.

In Ubuntu Tweak, go to Janitor -> System -> Old Kernel and you will be presented with all the Linux kernel packages on your system. The current kernel will not be included here, for obvious reasons. You can now pick and choose and select what you want to remove easily from here.

Tried with: Ubuntu Tweak 0.8.7 and Ubuntu 14.04

How to use Skype on Linux

Skype is not just used for audio or video chat, but for plain old text chatting too. I use Skype with a account on Ubuntu. I wish I could just chat from inside, like you can use GChat from inside Gmail web interface. There are Skype for extensions available for the major browsers, but they seem to install only on Windows. I could not install them on Linux. I wish this worked because it would be convenient to chat with Skype contacts directly from my webpage messaging sidebar.

Instead, I use the Skype client which is available for various Linux distributions. Just download that for your distribution here and install it. For Ubuntu, this downloads a multiarch .deb file. The recent versions of Skype client allow you to use your account. Just choose the Microsoft account option during login.

Tried with: Skype 4.2 for Linux and Ubuntu 12.04

Difference between Kinect for Windows and Kinect for Xbox 360 on Linux

There are two variants of the Kinect hardware. The first is Kinect for Xbox 360, the Kinect sensor that was released to work with the Xbox 360. The second is Kinect for Windows, a Kinect sensor that is almost the same as Kinect for Xbox 360 and can be used with any computer. Kinect for Windows has some extra features like near mode. You can also distinguish this type by the Kinect for Windows label below the base of the unit.

Beware that on Linux a lot of the drivers, libraries and applications for Kinect work only with the Kinect for Xbox 360! Knowing which type of Kinect hardware you are using will save you a lot of trouble.

Each type of Kinect is identified differently by the Linux kernel. This can be seen in the identification that is printed when you list USB devices.

The output for Kinect for Xbox 360 is:

$ lsusb
Bus 001 Device 058: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 001 Device 059: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Bus 001 Device 060: ID 045e:02ae Microsoft Corp. Xbox NUI Camera

Here 045e is the vendor ID and 02b0 is a product ID. Note that the Kinect is identified as 3 different products with a fully qualified product name, for example Microsoft Corp. Xbox NUI Camera.

The output for Kinect for Windows is:

$ lsusb
Bus 002 Device 011: ID 045e:02c2 Microsoft Corp.
Bus 002 Device 013: ID 045e:02be Microsoft Corp.
Bus 002 Device 014: ID 045e:02bf Microsoft Corp.

Notice how the product IDs are different from Xbox 360 and how the device name is just listed as Microsoft Corp. without any further description.

Tried with: Kinect for Windows, Linux 3.2.0-48-generic and Ubuntu 12.04 LTS

How to write a disk image on Linux

You may sometimes need to write a disk image to a USB thumbdrive or a SD card. This is typically done to create a system that you can use to boot a device. The image file typically has the .img file extension, though its not necessary and does not matter. Writing the disk image can be easily done on Ubuntu or any other Linux distribution.

  • Insert the USB thumbdrive or SD or microSD card to your computer. It should be detected and Ubuntu might mount it automatically. If it does not, that is okay as long as it is detected.

  • We need to find out what is the device file which represents the inserted USB thumbdrive or SD card as described here.

  • Before we write the disk image, we need to unmount the device. This can be done by passing the device name to the umount command:

$ umount /dev/sdb
  • To write the disk image we can use the dd command. Provide the disk image file as the input file and the device file as the output file with a suitable block size:
$ sudo dd if=/blah/foo.img of=/dev/sdb bs=1M
  • Finally, we flush the disk buffers to ensure that the writing is finished:
$ sync

That is it! The disk image is written and you can take out your USB thumbdrive or SD card to use it.

Related: How to write a disk image on Windows using Win32 Disk Imager

Tried with: Ubuntu 12.04

How to install CyanogenMod 10 to SD card on the Nook Color

Linux booting on the Nook Color
Linux booting on the Nook Color

The Nook Color is a 7-inch tablet that was created by Barnes and Noble. It runs a heavily customized version of old Android created by B&N. You cannot do pretty much anything in it other than read books bought from B&N. Thankfully, the Nook Color has a bootloader that is not locked and so it is easy to boot and load other operating systems on it. CyanogenMod has been ported to run on the Nook Color. This post shows you how to have CM10 running off a microSD card on your Nook Color. Your stock Nook OS remains safe and untouched!

CyanogenMod 10 booting up on the Nook Color
CyanogenMod 10 booting up on the Nook Color

CyanogenMod 10 is based on Android 4.1 JellyBean. At the time of this writing, there is no stable release of CM10 for the Nook Color. But, I found that the nightly releases work pretty well. Update: Stable releases of CM10.1 are now available for Nook Color from here. Please use that in the rest of this guide.

These are the steps I used to install CM10 on my Nook Color using a microSD card. This method is easy and safe to try and it leaves the original Nook installation as it is. You just need a microSD card of capacity 2GB or more. These steps are based on the detailed CM10 installation guide written by leapinlar.

CyanogenMod 10 running on the Nook Color
CyanogenMod 10 running on the Nook Color
  1. We need a Linux SD image to boot from and to install the CM 10 ROM. Download the image and unzip it to obtain a .img file.
  2. Create a bootable microSD disk image using the above .img file. This can be done easily on either Windows or Linux. Once it is done, remove the microSD card and then re-insert it back into the computer. It will be mounted.
  3. Download the latest CM 10 release for the Nook Color. Encore is the CyanogenMod codename for Nook Color.
  4. Without access to the Google Play Store to install apps, a CyanogenMod is pretty useless. To have the Play Store and other Google apps, download the GApps release for CM 10. Pick the gapps file that is meant for CM 10.0.x.
  5. Copy the CM 10 and gapps zip files to the microSD card. Do not unzip the files, just copy them directly. Eject the card from your computer.
  6. Ensure the Nook Color is charged to last at least 30 minutes. Power down the Nook Color. Insert the microSD card into the microSD slot of the Nook Color. The slot is on the back, inside the nook.
  7. Power on the Nook Color. The Linux image on the microSD will boot up, you will see the familiar Linux penguin image. Linux will install the CyanogenMod bootloader, CM10 and gapps from their zip files. After it is finished, it will power down the Nook Color.
  8. Now power up the Nook Color again and you will see the CyanogenMod bootloader, which will boot CM 10 from the microSD card. You will see the pulsing circle of CM 10 and should boot into CM 10 in a while.
  9. You now have CM 10 running on your Nook Color. Once you give Google your credentials, you will be able to install Android apps from the Play Store. Have fun! 🙂

If you ever need to use the stock Nook OS, just power down the Nook Color, remove the microSD card and power on again. And when you want your CM10 back, just insert the microSD card back into the Nook Color.

Note: I no longer use a Nook Color, so I cannot update the post with recent information. For the latest releases to use with this installation method, please see the comments below shared by other users.

Tried with: Nook Color 8 GB, SD image generic-sdcard-v1.3-CM7-9-10-larger-Rev5, CyanogenMod 10-20121228-NIGHTLY-encore and GApps jb-20121011-signed