Force new terminals to open in current terminal (using Tmux)


I’ve been increasing my linux mojo the past months and I’m bothered by the fact that every time I open a terminal (ctrl-alt-t) it opens up in a new window. A git window here, quick vim edit there, htop etc. Before I know it I have a lot of terminals I don’t even use anymore. Setting titles to tell the windows apart was a partial solution but not good enough for me.

Recently I discovered tmux which is a terminal emulator to work with multiple terminals in a single window. It’s somewhat advanced for me but I gave it a shot. You can download it using

sudo apt-get install tmux

A primer can be found here: It helped me out in getting started. After about a day I got the hang of the basic commands and loved it. Today I realised I could solve the problem of multiple terminals with tmux. So I will explain to you how I did it.

Step 1

We have tmux up and running. So by now you know you can run tmux attach to attach to any running session. Running tmux attach -d does the same thing. Except, it disconnects every other client (terminal window in our case) that is running that session. So if you are facing a terminal window with a tmux session and you type tmux attach -d in an other terminal window, the former will detach from the tmux session. So, first of all, we make sure that whenever we open up a new terminal we are dropped in a tmux session.

This is easily done by adding the following line on the bottom of your .bashrc file (e.g., by running nano ~/.bashrc):

[[ $TERM != "screen" ]] && exec tmux

Don’t close this file yet, because we’ll change it soon.

If you were to try this out you would see that everytime you open up a new terminal window it will open tmux. Great!


Next, when we open up a new terminal we want to make sure we jump to our previous tmux session and kill the other window. Easy enough.

First of all, change the line we added to our .bashrc previously to the following:

[[ $TERM != "screen" ]] && exec tmux attach -d

As you know by now, this will disconnect all other sessions. Since we start up tmux immediatly when creating a terminal, detaching from tmux closes our terminal. Excellent, we fixed it!

Step 3

When you would try this, don’t be suprised if you can’t open any terminals anymore. This is normal. When you have no tmux sessions running and you execute tmux attach -d, tmux will tell you you have no sessions and quit. Ergo, you need to tell tmux to create a session if there is no running session. Fair enough.

You should create or modify the file ~/.tmux.conf and add the following line (e.g., by running nano ~/.tmux.conf):

#if run as "tmux attach", create a session if one does not already exist
new-session -n $HOST

This piece of setting makes sure the new session is created when you run tmux attach -d when no sessions are present.

That’s about it!

– Christophe


Mounting Windows share in Ubuntu server terminal


I’ve been trying to properly mount a windows share using Linux today. I’ve got it figured out using bits and pieces here and there, so I’m sharing!

The server at has a share named “shareFolder”. We have login credentials for the server, being “admin” and “password”.

First of all, we need a directory to mount the drive to. For example, I created a directory “Windows” in my home folder.

mkdir ~/Windows

When you have the mountpoint, you might also need to install cifs-utils:

sudo apt-get install cifs-utils

Now we’re set to mount.

To simply do a one-time mount of a network drive we type in the following command:

sudo mount -t cifs -o username=admin,password=password // /home/Windows

*”-t” specifies the mount type, being CIFS. “-o” means “options”, which we append by comma separated values. If e.g you leave out the password parameter it will prompt you for your password.

If you now navigate to that directory and perform an “ls” you will see the directories and files.

To mount a drive automatically when you log in to your server we need to edit the “/etc/fstab” file.

sudo vi /etc/fstab

This has a lot of stuff in it, but you can disregard that. We need to append one line at the end being the following:

// /home/Windows cifs user=admin,password=password,uid=1000 0 0

If you have a shared folder with a space in the name, you replace the white space withΒ 40. I have a folder named “Seagate 2TB” so I have the following line:

//\0402TB /home/Windows cifs user=admin,password=password,uid=1000 0 0

The “uid=1000” is my ID on my client ubuntu machine. You can find this out by simply typing “id” in an empty terminal. This makes sure I am the owner of the share. Also, you can use single quotes for a one-time mount, but you can not use them in /etc/fstab!

To make things work you’ll need to reboot. To see if it works you can simply list the contents of the directory.

cd ~/Windows

And that’s how I got it working. I hope it can be of service for anyone πŸ™‚


Cyborg RAT 7 and Ubuntu 13.04

I’ve recently bought a mouse like this and it doesn’t seem to work properly with Ubuntu! The x-server freezes after 1 click. So I thought I’d share this quick fix πŸ™‚

You need to locate the following folder in your system:


Open a terminal (ctrl + alt + T) and enter “cd /user/share/X11/xorg.conf.d”

In this folder there should be a few configuration files, but disregard those. You will need to create your own configuration file for the RAT7 mouse as follows:

1) Create the file and open it with an editor to your choice. In my case VI. The number 910 is the priority of the configuration file. You might want to put that as the highest number to be sure πŸ™‚

sudo vi 910-rat.conf

You can also use nano “sudo nano 910-rat.conf”

2) Paste the following lines in there

Section "InputClass"
Identifier "R.A.T."
MatchProduct "R.A.T.7|R.A.T.9"
MatchDevicePath "/dev/input/event*"
Option "Buttons" "17"
Option "ButtonMapping" "1 2 3 4 5 0 0 8 9 7 6 12 0 0 0 16 17"
Option "AutoReleaseButtons" "13 14 15"
Option "ZAxisMapping" "4 5 6 7"

3) Reboot

sudo reboot

This should fix the problem for you πŸ™‚ Mind that the configuration file is in /usr/ and not in /etc/! This makes the x-server stop from starting.