Thursday, March 27, 2014

How to change font size of terminal emulators on the fly

There is no shortage of Linux X Window terminal emulators. For a power user who works long hours with the terminal, it is important to know how to zoom in, that is, make the text larger. Your strained eyes will thank you for it.

The table below summarizes how to increase and decrease the font size on the fly for an non-exhaustive list of terminal emulators.

Terminal emulators + font size - font size
xterm Shift + Keypad Plus(+) Shift + Keypad Minus(-)
GNOME terminal Control + Shift + Plus(+)
Do not use keypad.
Control + Minus(-) Do not use keypad.
Terminator Control + Shift + Plus(+)
Do not use keypad.
Control + Minus(-) Do not use keypad.
Konsole Control + Mouse Wheel Scroll Up, or
Control + Plus(+)
Control + Mouse Wheel Scroll Down, or
Control + Minus(-)
lilyterm Control + Plus(+)
Do not press Shift, or use keypad.
Control + Minus(-)
Do not use keypad.
xfce4-terminal Right Click/Preferences/Appearance. No keyboard or mouse shortcut.
lxterminal Edit/Preferences/Style. No keyboard or mouse shortcut.
mlterm Control + Right click to bring up settings. Encoding tab/Font Size. No keyboard or mouse shortcut.
kterm Control + Right click to bring up font size menu.
rxvt-unicode (urxvt) Doable but archaic. Issue printf command inside terminal window.
Eg: printf '\33]50;%s\007' "xft:DejaVu Sans Mono-8"

My next post aims to further reduce your eye strain by increasing the font size of virtual terminals.

Thursday, March 20, 2014

Identify Linux distribution, code name and version info

How do you identify the Linux distribution, the specific code name and version number that is running on a machine?

Below are several ways.

  1. lsb_release
    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Debian
    Description: Debian GNU/Linux 7.4 (wheezy)
    Release: 7.4
    Codename: wheezy

    If lsb_release is not installed by default on your machine, install it as follows.

    • For Fedora, Centos, and Red Hat Enterprise Linux
      $ sudo yum install redhat-lsb-core
    • For Debian and its derivatives.
      $ sudo apt-get update
      $ sudo apt-get install lsb-release
  2. Examine the distro release file (/etc/*release).

    The release file of a distribution contains the information we want. The specific release file name may vary by distribution, but the file is usually located in the /etc directory.

    $ ls /etc/*release
    $ cat /etc/os-release
    PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
    NAME="Debian GNU/Linux"
    VERSION="7 (wheezy)"
  3. /etc/issue
    $ cat /etc/issue
    Fedora release 19 (Schrödinger s Cat)
    Kernel \r on an \m (\l)

    This method is less reliable than the first two methods. The /etc/issue file contains the text to be displayed as part of the login prompt.

    The default file content varies from distro to distro. Also, the system administrator may have customized the file content.

    For default Debian wheezy, the file does not reveal the code name or the minor version number (the 4 in 7.4):

    $ cat /etc/issue
    Debian GNU/Linux 7 \n \l

Sunday, March 16, 2014

How to enable mod_rewrite for Apache web server

I've installed two Content Management Systems on my Debian wheezy system - WordPress and Drupal. The web server deployed is the venerable Apache. Common to the 2 deployments is the issue of how to enable the mod_rewrite module for the Apache web server.

The rewrite module maps obscure URLs - computer gibberish - to 'clean' URLs. The default URLs, for both WordPress and Drupal, are something like http://localhost/wordpress/?p=248.

You can configure the URLs to be rewritten to resemble the post titles: http://localhost/wordpress/a-board-game/. However, the change won't take effect unless the mod_rewrite module is enabled.

Query module status

To check if mod_rewrite is currently enabled:

  1. Create a PHP script to list the enabled Apache modules, and place it in the Document Root directory (by default: /var/www):
    $ cat > /var/www/testmod.php
  2. Run the script by entering http://localhost/testmod.php into a browser.

If the mod_rewrite module is enabled, you will find it in the output of the PHP script.

Enable rewrite

To enable:

  1. Enable mod_rewrite module.
    $ sudo a2enmod rewrite
    Enabling module rewrite.
    To activate the new configuration, you need to run:
      service apache2 restart
  2. Set AllowOverride to All in Apache configuration files.

    Apache configuration files contain directives to control web server behavior. The configuration directive we're interested in is AllowOverride. For Debian wheezy, look for the directive in /etc/apache2/sites-available/default.

    $ more /etc/apache2/sites-available/default
     <?Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all

    When the AllowOverride directive is set to None for a directory, then Apache ignores all .htaccess files in that directory and in its sub-directories.

    The .htaccess files are 'directory-level' Apache configuration files. Web applications such as WordPress and Drupal have a .htaccess file in their respective web directories.

    In the above example, AllowOverride is set to None for /var/www, the Document Root directory. Therefore, all .htaccess files are ignored in the entire web hierarchy.

    Modify AllowOverride to have value All.

     <?Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
  3. Restart Apache.
    $ sudo service apache2 restart
    [ ok ] Restarting web server: apache2 ... waiting .

Disable rewrite

To disable:

$ sudo a2dismod rewrite
Module rewrite disabled.
To activate the new configuration, you need to run:
  service apache2 restart
$ service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .

Tuesday, March 11, 2014

Part 2: Specify default applications for file types - file managers

Part 1 introduced the xdg-mime command to change the default application for a file type. If you want a GUI method, or more tweaking is required after running the command, this post is for you.

File managers can create file associations - the assigning of a default application to open files of a certain extension. Below is an example of changing the PDF default application using the Nautilus file manager for the GNOME desktop.

  1. Open Nautilus, and navigate to any PDF file.
  2. Right click on the PDF file, and select Properties.
  3. Click to open the Open With tab.

    Note that this screen identifies the current Default Application -Document Viewer, an alias for evince.

  4. Select the new default application.

    If you find the application you want under Recommended Applications, click the app and then the Set as default button. Otherwise, click the Show other applications button to display more application choices.


If the application you want, say xpdf, is not listed under Recommended or Other applications, first make sure that it is installed.

If the application is installed, but not listed in the Open with tab,

  1. Edit the application's desktop file - xpdf.desktop.

    The desktop file can exist in 1 or both of the following locations.

    • $HOME/.local/share/applications/xpdf.desktop
    • /usr/share/applications/xpdf.desktop
  2. Append %U to the end of the Exec= line.

    The Exec= line specifies the command and any arguments to start the application. If the Exec= line does not specify that the application can take command line arguments, the application is omitted from the Recommended applications and Other applications lists.

    The Exec= line in the xpdf.desktop file should look like the following:

    Exec=xpdf %U

    %U indicates that the xpdf command can take multiple URLs as arguments.

xpdf should now appear in the Recommended applications list.

Friday, March 7, 2014

How to specify default applications for file types: Part 1 - Command line

Numerous apps vie to open your PDF files by default - evince, xpdf, Adobe Reader, Okular, etc. If you don't like the default as dictated by your desktop environment, you can change it.

The general idea is that default applications for file types, or 'file association', is governed by a set of configuration files. Having said that, I wish an universal method existed to change file association that is independent of the Linux distribution, the desktop environment, the file manager, and the application. In reality, the desktop environment may choose to interpret the same configuration file in different ways, or use different files altogether. Below is the general procedure that has served me well.


If you are comfortable with command-line, then I'd recommend that you use the xdg-mime tool first.

Before we change the default application for opening a PDF document, let's identify the current default application.

$ xdg-mime query default application/pdf 

The above command requires that you know the MIME type of PDF files(application/pdf). My earlier post explains how to find the MIME type of files.

If evince is not the default program you want, you can change it to say xpdf as follows.

$ xdg-mime default xpdf.desktop application/pdf

The second argument - xpdf.desktop - specifies the default application in the form of its desktop filename. Every application must have a desktop file containing configuration information in order to be registered into the desktop environment's menu system. The global desktop file must exist in the /usr/share/applications directory. Local desktop files must exist in the ~/.local/share/applications directory for individual users.

Before you run xdg-mime, you must make sure that:

  1. The desktop file preexists in the right directory for your application.
  2. You provide the correct desktop file name as an argument to xdg-mime.
$ ls -l /usr/share/applications/*xpdf*.desktop
-rw-r--r-- 1 root root 181 Mar  4 10:13 /usr/share/applications/xpdf.desktop

The xdg-mime command inserts one line into the [Default Applications] section of the local configuration file for file association (~/.local/share/applications/mimeapps.list).


To verify that xpdf is now indeed the default application:

  1. Open a PDF file using the command.
    $ xdg-open somefile.pdf
  2. Double click a PDF file from inside your favourite file manager.

With my Debian wheezy system running GNOME 3, xpdf now opens PDF files by default from both the command-line and the Nautilus file manager.

If you are not comfortable with the command-line or xpdf does not open the PDF file by default from your file manager, the remedy is to configure the default application using your file manager. That will be the topic of part 2 of this series.

Tuesday, March 4, 2014

How to find the MIME type of a file

Some MIME types can be intuitive - application/pdf for PDF files. However, not all MIME types are that easy to get exactly right - application/ for xls or Excel files.

The following are different ways, using the command line, to identify the MIME type of a file.

  • xdg-mime
    $ xdg-mime query filetype somefile.xls
  • file
    $ file -b --mime-type somefile.xls
  • gvfs-info
    $ gvfs-info -a standard::content-type somefile.xls
      standard::content-type: application/