Prepend output with time to generate each line

To show how long it takes before showing each new line of output, use this neat command.

long_command | ts -i "%.s"
$ ./configure --prefix=/tools | ts -i %.s
0.082337 checking for a BSD-compatible install... /tools/bin/install -c
0.002841 checking whether build environment is sane... yes
0.008164 checking for a thread-safe mkdir -p... /tools/bin/mkdir -p
0.000040 checking for gawk... gawk
0.005892 checking whether make sets $(MAKE)... yes



  1. St├ęphane Chazelas at

Restart cinnamon from command line

When cinnamon freezes up and needs to be restarted, you can restart it from Cinnamon itself or from a different terminal.

In Cinnamon

Press ALT+F2. Type in the letter r and press enter.

On the command line

To switch to another console terminal, press CTRL+ALT+F2.
On this terminal, type this command.

pkill -HUP -f "cinnamon --replace"



  1. User sim at

Create, attach, detach disk to vm in kvm on command line

In kvm, let’s say you want to create a new disk and attach it to a virtual machine. You could use Virtual Machine Manager. But for the command line, here is a quick way how to do it.

Create a disk

Create a qcow2 disk that is fully allocated. When I tried with disks that were not fully allocated, the vm would only see the 200K or so and would not let me write a partition table large enough to do anything.

time qemu-img create -f qcow2 /var/lib/libvirt/images/vmname-vdb.qcow2 22000M -o preallocation=full

Attach a disk

You can omit the flags as needed, if you don’t want to update the virtual machine’s definition, or –config. And some of these are probably redundant, but they did not throw errors for me and I wanted the change to be immediate and persistent upon vm reboot, so I leave them all in.

virsh attach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --target vdb --persistent --config --live

Detach a disk

Same thing as the attaching, only you don’t include the –target flag.

virsh detach-disk --domain vmname /var/lib/libvirt/images/vmname-vdb.qcow2 --persistent --config --live



Man pages

  1. qemu-img

Remove scsi disk from operating system

To tell an OS you are ready to remove a scsi disk, you can run this command:

echo 1 > /sys/block/sdX/device/delete

Where sdX is the device you are ready to detach.

For virtual machines I don’t usually bother doing that, but that is how to safely tell GNU/Linux you are going to remove the device.



  1. Original question

Save settings for bc, the Linux calculator


Use a ~/.bcrc file with contents:


Execute this or put it in your bashrc:

export BC_ENV_ARGS=~/.bcrc


In GNU/Linux, a basic calculator is bc from package bc.
The normal output is displayed with zero values after the decimal point, so I like to adjust it to show me four numerals past the decimal point.


You can use whatever scale you like.
To get this to take effect every time you call bc, you can set an environment variable BC_ENV_ARGS to a filename. That file is parsed as regular instructions to bc, before it enters the interactive shell or interprets standard in.
So modify a file, such as ~/.bcrc with your instructions.
Update your shell (or add to your .bashrc file):

test -f ~/.bcrc && export BC_ENV_ARGS=~/.bcrc



  1. Inspiration for this post
  2. Description of “rc” files in Unix

man pages


Firefox disable don’t load tabs until selected


browser.sessionstore.restore_on_demand = False


When I tell my browser to run, I want it to load all of my previous tabs, as well as actually load the tabs. When I switch to it, it should be fast, because it as already loaded the content. I don’t want it to flash and load upon my selecting the tab; it should already do that!

There used to be an option in Firefox’s preferences for changing this, but it was removed from the gui. But it’s still there in about:config.



Find running X sessions


{ ps -eo pid,command | awk '/-session/ {print $1}' | while read thispid; do cat /proc/${thispid}/environ | tr '\0' '\n' | grep "DISPLAY" | sed -e "s/^/${thispid} $( stat -c '%U' /proc/${thispid}/comm ) $( basename $( readlink -f /proc/${thispid}/exe ) ) /;"; done; } 2>/dev/null | grep -iE "xfce|cinnamon"


I was working on a shell script that affects the running desktop environments. In order to find the running processes, owners, executable, and display session, I whipped up this one-liner.

Obviously here, I limit my searches to specific types of desktop environments. I was getting a dbus-daemon and at-spi2-registryd which I neither understand nor care about, so I added the regular expression search at the end. Feel free to modify for your own use.

Example output:

$ { ps -eo pid,command | awk '/-session/ {print $1}' | while read thispid; do cat /proc/${thispid}/environ | tr '\0' '\n' | grep "DISPLAY" | sed -e "s/^/${thispid} $( stat -c '%U' /proc/${thispid}/comm ) $( basename $( readlink -f /proc/${thispid}/exe ) ) /;"; done; } 2>/dev/null | grep -iE "xfce|cinnamon"
1791 bgstack15-local xfce4-session DISPLAY=:0

python readlink function


def readlinkf(_inpath):
   if os.path.islink(infile):
      return os.path.join(os.path.dirname(_inpath),os.readlink(_inpath))
      return _inpath



In GNU, there’s a fantastic utility named readlink. The main way I use it is to get the full and true path of a file or symlink.

For example:

$ ls foo .config/qux
.config/qux  foo
$ readlink -f foo

In python, I wanted to achieve the same thing. it is possible with the os.path.islink and os.readlink functions. Here is my quick function for a readlink -f, since I didn’t find a specific implementation that outputs the full path.




Online reference


Search expressions

  1. python detect if file is symlink
  2. python readlink