How to remove columns from a text file


I want to remove the 1st and the 5th columns of a text file of tab separated values. The file is as follows:

1.0   -3    3.4   2     7     9
-100  -30   -1    0     -80   7
70    7     8     0     3     0
71    4.5   2.1   0.6   37    4

Continue reading

Create “New Document” in Nautilus

In nautilus 3.63 the “New Document” has disappeared but you can easily add this option following these steps:

  1. Edit the file ~/.config/user-dirs.dirs
  2. You should set the XDG_TEMPLATES_DIR variable to “$HOME/Templates”. This is the content of my user-dirs.dirs file:

  3. Create an empty text file in ~/Templates. In a shell write:
  4. [user@mypc ~]$ touch ~/Templates/text.txt
  5. Open Nautilus and click with the right button inside a directory over a black space. You will find the option New Document->Text

You can create more templates, for example I have created one for html files. You just have to create a html file in “$HOME/Templates” with the following content:

<!DOCTYPE html>

Replace content of multiple files


Imagine you have some misspelled words in some documents:

$ grep Intalac *
file02.html: <h2 align="left"><a name="ubuntu"></a>Intalación en Ubuntu 12.10<img src="img/009-ubuntu.png" width="62" height="59"></h2>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>

In this case you want to change a word in all the documents.


You can use sed with vi commands:

sed -i 's/<original>/<replaced>/g' 

In this case we can solve the problem with

sed -i 's/Intal/Instal/g' *.html

Encrypt a file image in Linux


I want to create a ciphered file partition mounted on loopback.

Create crypto image

1. First create the file image which will contain all your encrypted data:

dd if=/dev/zero of=extra.img bs=100k count=1024

2. Load the cryptoloop kernel module:

sudo modprobe cryptoloop

3. Set up the loop device with your desired encryption algorithm. It will ask you for the password:

sudo losetup -e aes /dev/loop0 extra.img

4. Format the file partition and mount it:

mkfs.ext4 /dev/loop0
sudo mount /dev/loop0 /mnt/

Load the data partition

The next time you want to load the partition you have to repeat this steps:

sudo modprobe cryptoloop
sudo losetup -e aes /dev/loop0 extra.img
sudo mount /dev/loop0 /mnt/

Ubutu/Debian Users: By default, Debian systems run the password through a hash function. So if you have created your image in another distribution and want to load in Debian you have to add the “-N” option:

sudo losetup -e aes -N /dev/loop0 extra.img

Unload the data partition

To umount the partition:

sudo umount /dev/loop0
sudo losetup -d /dev/loop0