Word wrap a text file

Wrapping a text file to a fixed number of character is easy in Linux:


fold -w 80 -s input.txt > output.txt

Above -w 80 set the character limit to 80 which is standard. The flag -s tells to break lines at white space, not between words.

Convert text file to ASCII character encoding

It’s often needed to convert text between different character encodings, for example from UFT8 to conventional ASCII.
Linux systems come with command line tool iconv that does the job:


iconv -f utf8 -t ascii input.txt > output.txt

To see a list of all supported encodings do


iconv -l

Changing file permissions recursively

Every now and then you’ve got a massive directory tree whose reading permissions need to be changed. For example, all files readable to all users, all directories accessible to all users, all executables executable by all users.

This is easy enough to do with find and chmod commands. Assuming that the root of the directory tree is somedir:

Set all directories to rwxr-xr-x (a.k.a. 755)
find somedir -type d -print -exec chmod 755 {} \;

Make all files readable
find somedir -type f -print -exec chmod go+r {} \;

Change all 744 files, executable by the owner, to 755, executable by all:
find somedir -type f -perm 744 -print -exec chmod 755 {} \;

Filtering emails to subdirectories in GMail

I’ve used message filters in Thunderbird a long time and couldn’t really manage without them. I’ve also created filters for GMail mailboxes. But it would be nice to be able to add filtering in GMail itself, so that emails are always sorted regardless of the client I use to read them.

Here’s how:

  1. Create a subdirectory in Thunderbird or other emall client. GMail web interface doesn’t allow you to create a “real” subdirectory – creating a GMail label is not sufficient to make this work.
  2. Create a filter in Gmail web interface: click the down arrow in the search field, add search criteria, choose Create filter with this search.
  3. In the filter options, tick “Skip Inbox” and “Apply the label”, and choose the subdirectory created in step 1.
  4. If you want to filter all emails that already exists in Inbox, tick “Also apply filter to matching conversations.” as well.

Java or GTK applications crashing in KDE

In Kubuntu 13.10 Java applications seemed to crash at start up with the following error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f8f34cb9b3c, pid=25450, tid=140253340165888
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libgobject-2.0.so.0+0x31b3c] g_type_check_instance_is_a+0x3c
#

The same error occurred regardless of the Java Runtime Environment installed. Some GTK applications are also affected.

As mentioned (and in many other bugs) this is related to the KDE oxygen-gtk theme.

Solution:
In System Settings -> Application Appearance -> GTK change GTK2 and GTK3 themes to something else than oxygen-gtk.

Thunderbird 16.0.2: Account exceeded command or bandwidth limits failure

Ubuntu 12.10 (Quantal Quetzal) ships with Mozilla Thunderbird 16.0.2. This version of Thunderbird suffers from a bug related to repeatedly downloading IMAP account content. In my case Gmail account returned the
The server returned the error: Account exceeded command or bandwidth limits.
error message daily, and the account remained blocked until the next day. Even when working, reading the Gmail account was painfully slow.

The remedy is to update to Thunderbird version 17.0, not yet included in Ubuntu 12.10, but available in the Ubuntu Mozilla Security Team PPA repository.

sudo add-apt-repository ppa:ubuntu-mozilla-security/ppa
sudo apt-get update
sudo apt-get install thunderbird

Fixing font sizes in MATLAB under Ubuntu

MATLAB runs in Ubuntu 12.04 without any major problems. However, one issue that I noticed was that changing the font size in figures has no effect; the text always appears in default (small) size in Matlab. The correct font size has an effect only in exported PDF and EPS files. The font spacing is incorrect though, as it seems to be based on the fonts that Matlab uses. As Matlab is often used (only?) for making figures, this can be a major problem.

As mentioned in this thread, the problem is related to Matlab not finding the correct fonts in Ubuntu OS. As a remedy install the following packages:

sudo apt-get install xfonts-100dpi xfonts-75dpi

and logout and login again. Matlab should now be able to show the plots in correct size. The fonts do not look pretty, though, which is probably related to broken anti-aliasing. Maybe there are other broken dependencies?
However, exported PDF and EPS files should now have the correct font spacing (e.g. the size of the legend box) and should be usable.

%d bloggers like this: