Adventures in Red Hat Enterprise Linux, CentOS, Fedora, OpenBSD and other open source solutions.

Impress friends with 5 vi(1) tricks

If ever you need to persuade a friend/colleague to use vi(1) instead of emacs(1) or nano(1), here are a few tricks that are cool in vi(1).

1. Replace all occurrences of "window" by "penguin"

Press escape a few times to enter command mode and then type the magical string:


The g at the end is optional, it means "global" and continues in a line instead of skipping to the next to search for other occurrences.

2. Load/read a file into the file you are editing

Press escape a few times to enter command mode and then use:

:r /path/to/file

You now have inserted that file into your current session.

3. Load/read output of commands to the file you are editing

Press escape a few times to enter command mode and almost the same as above:

:r!grep pattern file

Wow, this is cool!

4. More ways to save (and end) your file

After pressing escape a few times again, you can save (and quit) using these tricks:

  • :wq! Write, Quit and overwrite if existing.
  • :x Same as :wq!
  • ZZ Save and quit.

5. Moving around quickly

Here are a few tricks to move the cursor faster:

  • :10 Go to line number 10. Perfect when scripts stop and tell you what line caused the error.
  • G Go to the end of the document, beginning of that line.
  • $ Go to the end of the line.
  • 0 Go to the beginning of the line.

Good luck with vi(1)

Mythbusting 5 UNIX/Linux myths

Inspired by Discovery Mythbusters. Lets take a look at a few myths around the different shells and other Open Source or UNIX/Linux components that exist. To test these myths in a science-grade method I have asked my 4 direct colleagues to comment on these myths. Thanks Alan, Murat, Erick and Maxim!

The Korn Shell (ksh) is for old people

  • Alan: Middle-age
  • Murat: Neutral-age
  • Erick: Shit-head-age, but okay to use for OpenBSD because of license
  • Maxim: Not-old-age
  • Robert: Old-stubborn-age

plausable - busted

The Bourne shell (sh) is for UNIX, the Bourne Again (bash) shell for Linux

  • Alan: Is it a movie? Could well be.
  • Murat: Not true, both can mix.
  • Erick: True!
  • Maxim: Don't know.
  • Robert: Partially true.

plausable - busted

The Turbo C Shell (tcsh) is for programmers

  • Alan: Yeah.
  • Murat: Don't think so, every shell is okay.
  • Erick: No opinion.
  • Maxim: Don't know it.
  • Robert: Agree.

plausable - busted

Solaris is actually SLOWlaris

  • Alan: No!
  • Murat: Don't know, don't think so.
  • Erick: Not true!
  • Maxim: No
  • Robert: Not always true.

plausable - busted

OpenBSD is more secure

  • Alan: Supposedly
  • Murat: That's what they say!
  • Erick: Yes and no.
  • Maxim: Yes
  • Robert: Mostly yes.

plausable - busted

UNIX/Linux permissions on file/directories

I understand from non UNIX-ers that permissions can be challenging to understand. This article should get you going on any UNIX/Linux like operating system.

Each file (or directory) has a permissions based on identity:

  1. User this is the single person that owns the file.
  2. Group maybe users are part of a group.
  3. Other this is the rest of the world.

And each identity (user, group and other) can have a set of permissions. These can be expressed in more than one way; the whole word, the character representation of it or the numerical representation of it.

  1. Read or R or 4 the identity is allowed to read the file
  2. Write or W or 2 and now an identity is able to write to a file
  3. Execute or X or 1 makes identities being able to execute

Now that you know this, lets take a look at a listing of a few file, using ls(1) command: ls -l.

$ ls -l
total 16
drwxr-xr-x  2 robert users 4096 Dec 27 14:51 bin
-rwxr-x---  1 robert users 31 Feb 14 09:13
-rw-r--r--  1 robert users 13 Feb 14 09:12 textfile

The first column represent these permissions, the third and fourth column refer to user and group. So; the directory "bin" has these permissions: drwxr-xr-x Lets go over the individual characters:

  1. d This "thing" is a directory. For files it's a - sign.
  2. r This is the User part. The user has "read" permission.
  3. w The user has "write" permission. (Which means he can make new files inside this directory.)
  4. x The user has "execute" permission. (Which means he can change directory (cd(1)) into this directory.)
  5. r This is the group part, the group can read.
  6. - This is where "write" could have been. The group can't write in this directory.
  7. x The group has execute permission, the group is able to go into the directory.
  8. r This is the "other" (not user nor group) part. Everyone else can read.
  9. - Others can't write.
  10. x Others can execute/go into this directory.

You can repeat the same for those two other files. The difference is that and textfile are not directories, so:
Write means to have the ability to write in that file, aka modify.
Execute means the file can be executed, if there is code inside that actually does things, you are normally dealing with a program.

If you would express permissions with a number, you first split up the three parts, then count permissions for each part. For example:

  • rwx = 7 (r=4, w=2, x=1)
  • r-x = 5 (r=4, x=1)
  • r-- = 4 (r=4)

Some logical combinations are:

  • 777 everybody can do anything. (This can be dangerous!)
  • 750 user can do anything, group can't write, other can't do anything.
  • 640 user can read/write, group can read, others can't do anything.
  • 000 everybody can't do anything. (Except root) (This functionally locks files or directories)

Some strange combinations are 057, 077, 040, 007, etc.

Good, you are almost up to speed. One thing remaining; how to set or modify these permission. There are a few tools to help you:

  • chmod(1) Change (permission) modes for a file or directory.
  • chown(1) Change owner (and optionally group) of a file or directory.
  • chgrp(1) Change the group of a file or directory.

So, when you create a file, and would like to restrict a file to be only readable by the owner, you would use this command:

$ chmod 400 file

You could also use the more readable syntax of chmod(1):

$ chmod o-rwx,g-rwx,u-xw,u+r file

This tells chmod to (in order) remove (-) read write and execute (rwx) permissions for the others (o) of file. Then also remove all permission for the group, remove execute and write permissions and add read permissions to the user.

As using the human readable syntax for chmod requires more typing, it is almost better to use the numerical format. The only exception is when you only want to add on permission (like execute) without interfering with already existing permissions.

chown(1) is used change the owner of a file. It's rather straight forward:

$ chown robert:users

You can also remove that :users part to only change the owner of a file

chgrp(1) is even more straight forward, it changes the group of a file or directory:

$ chgrp users file

You have learned a major component of UNIX/Linux/*BSD operating systems. If you need more help, also see the man(1) pages of chmod(1), chown(1) and chgrp(1) by typing man chmod for example.

Open Source does not mean free

In my profession (UNIX/Linux and *BSD environments) Open Source is commonly used. My personal vision is that Open Source does not specifically imply free. Let's see what a randomly selected group of people answer to the question:

"Is Open Source software Free software?"

Person 0: No, for example Linux is not free; you are not free to do what you want.
Person 1: Open Source is not Free Software. Open Source is possibly free.
Person 2: Linux is financially free.
Person 3: Yes, Open Source software is free.

Wow, the answers are actually not what I expected. There is a difference in interpretation of Free. Lets take a look:

It seems that I was only thinking about the financial side of free and had forgotten about the functional aspects of free!

XML sitemap showing ugly URLS instead of URL paths in Drupal

If you see all the ugly URL's in your sitemap.xml, like /node/123, but have URL paths specified for those nodes, here is how to fix the problem:

  1. Deactivate "XML Sitemap Node" module. Your sitemap.xml will now not contain nodes anymore.
  2. Uninstall "XML Sitemap Node" module. This will remove all nodes from the sitemap.
  3. Activate "XML Sitemap Node" module. This will read all nodes and place them correctly into the sitemap.

It's that simple, but can make a huge difference, because you need to let search engines know how to access nodes based on your URL paths rather then the node number. Read more about SEO.

Making Linux commands shorter

Here are a few ways to shorten your Linux/UNIX/*BSD commands. Keep in mind that some short commands are less readable by others.

Long version Short version Characters won Application
cd $HOME cd 6 Shell
cat file | grep -v some | grep -v thing grep -vE 'some|thing' file 13 Shell
sort file | uniq sort -u file 4 Shell
:wq! :x 2 vi
boot bsd bsd 5 OpenBSD bootloader
grep -v '^#' file | grep -v '^$' grep -vE '^#|^$' file 11 Shell

Google Maps Mobile knows where I am (approximately)

This feature can change the mobile market, just as built-in camera's have, possibly more! If you download Google Maps for your mobile phone, you can use My Location. It does not use GPS but uses GSM antenna information to know where you are. This is not as accurate as GPS, and costs data, but if you have no GPS and have a data-plan, this is a cool feature. Take a look at this video:

Now what could be the next steps:

    Integrate with friends locations. Know where your friends are! Imagine being at a party, checking your phone to see if any other friends are there!

    Wardriving with only your mobile phone. If your phone supports WLAN, use it to scan access-points.

    Chatting to strangers nearby. Imagine a chat program that enables you to find people that have "Chat with anybody" set as a preference.

    Geocaching. GPS is more accurate, so this would require more descriptive hints, but it's possible!

Here in The Netherlands it tells me it is accurate within 1700 meters/1.1 mile, but the dot is acutally only 400 meters/0.25 miles away. I guess that mobile geographic application will dominate the future.

Using $GENERATE for PTR and A records

I was looking how to generate A records with the bind trick $GENERATE. There are lots of small articles available about setting up reversed lookups, but I could not easily find how to use this trick with A records. Therefore, here are my lines:

Forward or A record

$GENERATE 32-127 $ A 192.168.1.$

This will generate names like

Reverse or PTR record

$GENERATE 32-127 $ PTR $

This will generate the reverse part, it will enable you to do a host and get back the result.

5 ingredients for a good blog article

After reading many blogs and articles, I have discovered these basic ingredients keep me interested:

5. Short articles don't scare me away
Long articles make me loose interest when I see them. Shorter articles can be much more informative. I only take a minute, maybe 2 to read your article.

4. The essence keeps me interested
Some articles go into (not very interesting) details. This makes me loose interest too.

3. Structured articles help me
I want to be able to see the structure of the article/information within seconds. Using lists (<ol> and <ul>) and headings (<h2> or <h3>) helps.

2. Specialized topics interest me
I don't want to read news-paper style articles, otherwise, I would have bought a news paper. I am on the internet because I can read all these special articles.

1. The title should capture all information
I skim through websites only reading titles. Only if a title interest me, then I will stop scrolling and read that article.
A good example is the titles used at Boing Boing.

Help Network Solutions obtain idiotic domains

I was amused after reading this Network Solutions domain name registration story, I tried it for myself. Check out how easy it is to make Network Solutions pay another few Euros/Dollars:

1. Check if a domain is available

You can use online services, but whois from the command line like this:

$ whois

2. Check with Network Solutions

A stupid web-form on Network Solutions will say the domain is available for you to register. Meanwhile, Network Solutions has registered the domain.

3. Check whois again

As you can now see, Network Solutions has registered the domain. This process takes a few minutes only.

$ whois
   Whois Server:
   Referral URL:
   Status: clientHold
   Updated Date: 21-jan-2008
   Creation Date: 21-jan-2008
   Expiration Date: 21-jan-2009

The domain is in "clientHold" status for a year now. How rude is that? There will be many people shopping/browsing free domains using Network Solutions that are now only able to use Network Solutions to register their domain. (Or wait a year until it is free again...)

Registering a domain costs money, so I suggest you type in many idiotic domain names that nobody will ever be interested in. Some suggestions:

  • Combination of four or more words.
  • Words that are misspelled.
  • Words that do not exist.
Syndicate content