Centralized BASH history with timestamps

For every Unix user, there comes a point where shell history suddenly becomes very relevant. You learn to consult it, then start recovering the last command, then switch to searching past commands history to save precious time normaly taken typing.
Shortly after such a point in your life, you'll probably want to enhance your shell history in two very common ways:
  1. Make sure every terminal window can update AND access your centralized shell history. So you run a command or two in one window, then type "history" anywhere else and see them two commands right there.
  2. Provide meanigful timeline, this is done with timestamps. Very simple and powerful change helps you see exactly when each command occured.

Here's how you achieve both of these massive improvents to your history in BASH. Just add this to /etc/bashrc on your Linux system:

export HISTTIMEFORMAT="%d.%m.%y %T "
export HISTCONTROL=ignoredups:erasedupsshopt -s histappend
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r;"
export HISTCONTROL=ignoreboth

Enable Text Console Support in Ubuntu

There are three ways to access the command line interface in Ubuntu, as on any Linux and UNIX distribution. One is launching the terminal emulator program within the graphical user interface. The other two are about accessing the console directly, independent of the graphical user interface and the windowing system powering it (typically X server), and that's what we're concerned with here.

The quickest way to get to the console in Ubuntu is to just press Ctrl-Alt-F1. You will immediately be thrown out of the GUI and into the clean Linux console where you can log in and use the command line. Multiple console terminals are available this way if you press Ctrl-Alt-F2, Ctrl-Alt-F3, and so on.

However, what you might want is to get into the text console when you boot into Ubuntu instead of booting directly into the graphics mode. For that you'll need to make some configuration changes to your GRUB bootloader. The configuration file you will need to modify is /etc/default/grub, and it is a good idea to make a backup of it first in case you ever want to come back to the original configuration:

sudo cp /etc/default/grub /etc/default/grub.backup

With that out of the way you can start modifying the configuration file by opening it, with superuser privileges, in a text editor such as nano:

sudo nano /etc/default/grub

Enter your password and the file will open. Then look for this line: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash". Using nano you can search for this line by pressing the Ctrl-W shortcut and typing that line in. You just need to comment it out by putting a hash character in front of it so it looks like this:


As you might guess this disables booting with the splash screen, and the "quiet" mode, meaning it wouldn't hide the console output during boot.

Next enable the text mode finding GRUB_CMDLINE_LINUX and adding the "text" option to it. The line will then look like this:


This will ensure that you see the text output, but still doesn't enable the console login. For that find the #GRUB_TERMINAL line, which is likely commented out, uncomment it by removing the # character, and add the "console" option to it so it reads like this:


Finally save the file, which in nano you can do by pressing Ctrl-X and then enter, and make sure to update GRUB with the new configuration using the update-grub command:

sudo update-grub

Now you can reboot and Ubuntu should boot in the text mode, and allow you to log in to the console and run the desired commands.

How to Change tmux Meta Key to a Better One

The tmux tool, or the terminal multiplexer, is great for allowing you to run multiple terminals side by side. What's even better is that you can somewhat customize its behavior using the tmux.conf file. The meta key is the prefix you press before you issue a command that controls tmux so you can, for instance, split the terminal in two. By default it is set to CTRL-B, and this is how you can change that.

First create the tmux.conf file in your home directory

nano ~/.tmux.conf

This will open the nano text editor where you can enter the contents of the file. To change the prefix to CTRL-Y, for example, you would enter this:

### command prefix
unbind C-b
set-option -g prefix C-y

Then save the file by pressing CTRL-X and hitting enter to confirm.

As you can see the unbind C-b option tells tmux to rescind the default keyboard shortcut, and the set-option -g prefix C-y tells it to set a new one as the prefix, which is CTRL-Y. So if you have a different shortcut in mind just replace C-y with something else, like C-Space for CTRL-Space, which might actually be a great option. If you want to bind the windows key you could try Super_L.

If you're not sure which key codes represent which keys on your keyboard you might want to run xev and then press the desired keys to get their codes. The caveat is that for xev to work you'll need to have X installed and running, which will be the case on any desktop Linux system.

How to update grub boot loader config

GRUB boot loader starts up what's necessary for your Linux or UNIX system to boot up. You can edit its settings, like various boot options and which operating systems to select from, by editing the the /boot/grub/grub.cfg or /etc/grub.conf depending on your system. Graphical programs are also available for this purpose. See our GRUB Boot Loader overview for more.

Once you've edited your configuration you'll need to update grub to use it. This is very easily done by this single command:

sudo update-grub

Then once you reboot your new config should be active.

How to use dpkg to compare two Linux servers

While we mainly install, remove, update and otherwise manage software on Debian and Ubuntu based systems using apt-get, the lower level packaging system that apt-get actually relies on is dpkg.

You can use dpkg to list all of the installed packages on the current system. Do this by passing the –get-selections option. The following is the command that would get all of the packages, sort them, and list them into an installed-packages file.

dpkg --get-selections|sort > installed-packages

Now you can do the same on your second Debian or Ubuntu server except you might want to name your file something like installed-packages2.

With those two files ready you can now compare them. Copy over the first file to the second system (or vice versa) and run the diff command to see the differences.

diff -u installed-packages installed-packages2 > compare-servers

This would compare the two lists and throw the results into compare-servers text file. Name it whatever you like. The -u option makes the results a little more readable, but you can alternatively use the -y option which will format the results in two columns, first representing the first file, and second representing the second file.

Studying the differences between package lists can help you figure out what the differences are between two server setups in terms of installed software, what does one have that the other doesn't. If you want to replicate installed packages of one system to another, or in other words, install all of the packages which are installed on the first system to the second system, you can do that with dpkg and apt-get.

First run the following to get dpkg to select packages to install, marking them for installation:

dpkg --set-selections < installed-packages 

And then run this apt-get command to get those packages installed:

apt-get dselect-upgrade

This also allows you to quickly and easily restore a given system after a fresh install, if you've saved the list of installed packages from a previous system before you deleted it. It is also possible to compare and restore system settings from the /etc directory, but that is beyond the scope of this post.

How to install unrar in linux

The unrar program, which serves to open and extract popular .rar archives, is often available for install from repositories of a given Linux distribution. That should make installing it easy by using your distribution's package management system. That can be either a graphical user interface program like Ubuntu Software Center, or a command like tool like apt-get.

Some distributions may, however, require you to enable or add an additional repository to those included by default, which is usually the one containing various proprietary packages. This is because unrar, with the exception of the unrar-free package (which doesn't support all .rar files), is proprietary software. It's not open source. Some distributions avoid including non-free or non open source software by default, because they want to encourage using only Free Open Source Software, either for philosophical or practical reasons.

With that said, here is how to install unrar in the few most popular Linux distributions.

Ubuntu, Linux Mint

This also covers all of the Ubuntu variants like Xubuntu, Kubuntu, and Lubuntu. I know, those names are kinda hilarious when you string them together like that! But on to the install:

sudo apt-get install unrar


Debian is the grandaddy of Ubuntu, but it follows a quite different philosophy, and so does not enable the non-free repository by default. To enable it run (or copy-paste) the following command:

sudo echo 'deb ftp://ftp.us.debian.org/debian/ wheezy non-free
deb http://security.debian.org/ wheezy/updates non-free deb http://volatile.debian.org/debian-volatile wheezy/volatile non-free' >> /etc/apt/sources.list.d/wheezy.non-free.list

If by the time you read this you're running a newer version than Debian 7 (codenamed "wheezy"), just replace "wheezy" above with the new codename.

After adding the repository you should update the package database to make new packages available for install:

sudo apt-get update

And then you can install the same way you would in Ubuntu:

sudo apt-get install unrar  


In Fedora you need to add a RPM Fusion Non-Free repository before you can install unrar. Not to worry, this is pretty easy. Just follow the simple instructions provided at RPMFusion.org.
It involves downloading and launching a couple of files, and following prompts on the screen. Command line set up options are also shown.

Once you have it you can simply run the following command to install:

sudo yum install unrar

Speaking of Fedora it may be worth mentioning that Korora, a Fedora-based distribution, enables this repository by default so if you use Korora all you need to do is run the above yum command.


sudo zypper install unrar

That should be it for openSUSE since the "non-oss" (non open source) repository, which contains unrar, is added and enabled by default.

Arch Linux

pacman -S unrar

Same story as openSUSE.


If you're running any other Linux distribution chances are it is a derivative of any of the above or otherwise contains unrar in its official repositories. As a last resort option, which you probably wont need, you can download unrar directly from the RarLabs web site.

The RAR for Linux package, available for download there, contains both unrar and rar binaries as well as the makefile that allows you to easily install them. Just extract the package to any directory, then in the command line change the directory you are in to the extracted directory, and run the make command as a superuser.

In other words:

cd Downloads/rar/ && sudo make

The make command will copy the binaries to locations where Linux is looking for binaries, so you can run the rar and unrar commands as normal.

Don't do this, however, unless you really have to. Chances are your distro has unrar packaged up already and available for install. You can also check for that at pkgs.org (if your distro is listed).

7zip ubuntu

7zip is a versatile open source file archiver that uses the high compression 7z archive format, but also supports many others including ZIP, GZIP, BZIP2, TAR, WIM, XZ for both packing and unpacking, and even more for just unpacking such as RAR, ARJ, CAB, DEB, DMG, MSI, RPM and others. Check out the 7zip web site for more information.

Install 7Zip

7Zip is available for Ubuntu, and Linux in general in form of p7zip, which is a cross-platform version of the program. It is readily available for install from Ubuntu repositories using the Ubuntu Software Center or the APT tool. You can also install 7zip-rar to include RAR support in 7Zip.

Therefore, to install 7zip in Ubuntu simply search for it in the Ubuntu Software Center and install from there. If you want 7zip-rar tick the "Non-free rar module for p7zip (p7zip-rar)" checkbox from Optional add-ons.

To install both packages quickly from the command line just open the Terminal and run the following APT command:

sudo apt-get install p7zip-full p7zip-rar

That's all there is to it! Now you can use 7zip to package and unpackage files and folders using both command line tools 7z and 7za, and graphical tools like Ark, File Roller, and even the Nautilus File Manager.

Using 7Zip

To compress an archive of files and folders with 7Zip into a .7z compressed archive run the following command:

7z a pictures.7z Pictures/

In this example we compressed the Pictures folder into a pictures.7z archive. The "a" function stands for "add" or "archive" for adding specified files to the archive. We can also specify an absolute path to files and folders we want to compress by replacing Pictures/ above with, for example, /mnt/data/Pictures/.

We can also use 7z to compress folders into an archive of a different type, such as ZIP, by passing a -t switch followed immediately by the archive type. To create a pictures.zip we would then run the following:

7z a -tzip pictures.zip Pictures/

To unpack the archive to a specified location we would use the "e" function, which stands for "extract", like this:

7z e pictures.7z

This would extract files and folders to the current directory we are in.

Of course, you don't need to use the command line to compress and extract files with 7zip. Having it installed in Ubuntu automatically integrates it with Nautilus, the Ubuntu's File Manager, which allows you to seamlessly extract 7z and other archives by just right clicking on it and choosing "Extract here".

To compress files and folders just select them, right click, and choose "Compress…". A dialog will open that allows you to select 7z as the format, among many others.

Besides Nautilus having 7Zip installed also adds 7Zip support to other archiving tools such as File Roller and ARK so they can be used as normal to handle 7z archives, and others supported by it.

Ubuntu rar

RAR is a popular proprietary file format and software for compressing and archiving files, known for its ability to span multiple RAR files into a single archive, which is useful for compressing, archiving, and transferring large files.

Linux, including Ubuntu, has had RAR support for some time, but due to RAR's proprietary licensing and restrictions support comes through multiple programs. Luckily all of them are easy to install, and if you don't particularly care for the license you might just want to install them all in one go, especially unrar-nonfree and rar, and enjoy complete support for all RAR files, and all operations it allows you to do.

The following are the relevant programs and what they support, by their package names:

  • unrar-free – opens some .rar files, does not support RAR v3.
  • unrar-nonfree – opens all RAR files.
  • unar – an alternative option with full RAR support
  • 7zip – supports opening and extracting rar files
  • rar – a program for both creating and extracting rar archives

That about sums up what we've got, in addition to graphical archiving applications that use the support of some of these programs to handle rar files, among others.

Now let's try to keep it simple. If you just want the ability to open and extract all rar files, and also easily create rar archives then install unrar-nonfree and rar using the Ubuntu Software Center or with these simple apt-get command:

sudo apt-get install unrar-nonfree rar

With this stuff behind the scenes your Ubuntu can now do anything you want with rar files, right from the File Manager itself. Just right-click on any .rar file and choose "Extract.." and you're done. Or if you want to compress some files just select them, right click, and choose "Compress…". Then pick .rar from the list of formats and click "Create". You can then also use File Roller, Ark, and similar programs with rar files as well.

If you prefer to decompress with the command line here are a few basic examples to get you started. To extract an existing .rar archive run the rar command with the "e" function, which stands for "extract":

rar e pictures.rar

You can also use the unrar command the same way:

unrar e pictures.rar

To create a new archive run rar with the "a" function, standing for "add" or "archive", like this:

rar a pictures.rar Pictures/

You can also add multiple files into the archive:

rar a pictures.rar picture1.jpg picture2.jpg picture3.jpg

And just to make things slightly more interesting here's how to create multipart rar archives, those that take the original big file and compress it into multiple .part01.rar, .part02.rar etc. files.

rar a -v50M movie.rar movie.mp4

The "-v50M" tells rar that each rar part will be 50 megabytes in size. You can put any size here. For example if you want 5 MB for each part you would type "-v5M" instead. Extracting these files works the same way as extracting any other archive except you have to extract the first part, the .part01.rar, like this:

rar e movie.part01.rar

It will then take data from all the parts and put it together into the original file.

For more information you can consult the manual pages for rar by running man rar. Don't mind it saying "this is a trial version". It's the same kind of perpetual trial as WinRAR on Windows.

And that's how you roll with rar on Ubuntu.

Linux pause process

Linux allows you to pause a running process rather than quitting or killing it. Pausing a process just suspends all of its operation so it stops using any of your processor power even while it still resides in memory.

This may be useful when you want to run some sort of a processor intensive task, but don't wish to completely terminate another process you may have running. Pausing it would free up valuable processing time while you need it, and then continue it afterwards.

To pause a process in Linux we first need to obtain it's PID, or Process ID number. There are various ways of getting the PID, and here are two. The simplest is the pidof command with the name of the program you wish to pause:

pidof totem

Another way is to use a ps command and search through the results for the program name:

ps aux | grep totem

In this command ps aux lists all of the processes, the pipe sign tells it to filter by the next command (so called piping), and the next command, which is grep totem, searches through the results to display only those mentioning the totem process. The first number in the results should be your PID.

Once you have your process ID you can pause this process by running the kill command with the -STOP option followed by the PID number:

kill -STOP 10463

Of course, the above number is just an example. Replace it with your own. In this example the above command will stop Totem from running.

Totem is a nice example to try out because you can see the immediate effect if you're playing a movie in it. The movie will stop the moment you run this command. This isn't the same as pressing the "pause" button in the player controls, because the whole process is completely suspended, not just the playing of a movie. You can see this by trying to press any of the control buttons; they wont respond. The program is frozen, even though you can still move its window.

To continue the process just run the kill command with the -CONT option and your PID:

kill -CONT 10463

If you've been playing a movie in Totem, as per this example, your movie would immediately proceed and the button controls in it will work as normal.

And that's how you pause and continue processes in Linux!

How to Find Directories Larger Than 1GB in Linux

Finding out sizes of files and directories in Linux is done using the du command, which estimates their disk space usage. The du command can be used with options that allow you to customize the results you get.

Commands can also be combined with each other so the second command filters the results output by the first command. So to find directories that are larger than 1GB you can run this command:

du -h --max-depth=1 / | grep '[0-9]G\>'

The -h option displays the sizes in a more human readable format, in gigabytes rather than kilobytes. The –max-depth=1 option makes it display the sizes of only the directories immediately within the specified path, in this case the root path /, which in Linux includes directories like /home, /usr, /bin, /var, and so on. If we were to specify 2 it would go a level further and also look into directories like /home/user, /usr/bin, /var/log, etc.

The | sign is the pipe sign that allows combining the first command with the next command, in this case grep, which is used for searching through text output for the specified strings, which can be specified through regular expressions. So the grep '[0-9]G>' searches through the du output and displays only the files that are larger than 1GB.

Here's another example of this command, but with –max-depth=1 being shortened to -d 1, which works the same, and checking the /var directory instead of the root / directory.

du -h -d 1 /var | grep '[0-9]G\>'

This single command is all you need for this task, but there's an even shorter one that works well too. You can use the built in -t or –threshold option of the du command like this:

du -h -d 1 -t 1G /

It will display first level directories larger than 1GB within the root / path, just like the first command. If you want it to display all directories, not just first level, just leave out the -d 1 option.

Finally, as a bonus, you can sort the results from largest to smallest by piping in the sort command:

du -h -d 1 -t 1G / | sort -hr 

You can also sort the first command like this too, in which case you're combining the three commands into one:

du -h --max-depth=1 / | grep '[0-9]G\>' | sort -hr 

´╗┐Those are some of the ways you find directories larger than 1GB, or any other size you desire for that matter. Just switch 1G to 2G or 500M and so on.