Linux Tips and Tricks

On this page I have gahered some small hints for use of commands to achieve various tasks on a Linux system.

Sorting the password/group file on UID

If you like a tidy Linux system, here is a way to sort /etc/passwd based on the UID (3rd field):

[root@broken ~]# sort -nt: -k3,3 /etc/passwd >

The result is written to a new file, and should be checked before the passwd-file is overwritten. Since the GID is the 3 field in /etc/group, a similar command can be used to sort this.

Changing file-encoding in Emacs

After having used ISO-8859-1 encoding since I started using Linux, I have finally started the transition to Unicode. This means using a UTF-8 aware terminal, UTF-8 encoded filenames and UTF-8 encoded files. When opening a file in the Emacs editor, the status bar just above the minibuffer shows whether the file is UTF-8 encoded. This is represented by -u:-- in the beginning of the line, before the buffer name.

To change the encoding of the file, press C-x RET f and type the desired encoding. For example to change the encoding to UTF-8, press <CTRL>-x, then <Enter>, then f, and finally type utf-8. For ISO-8859-1 type iso-8859-1 instead. When the file is saved it will use the new encoding.

Last updated: 2007.03.03