Linux Commands: nl

There is an incredible selection of little Linux commands that will do all sorts of things to your files, standard output and programs. Now and again I’m going to pick one out and have a play because you just never know when a little tool already exists that will do exactly what you need.

Today I’m going to look at nl, which prepends line numbers to any file that you pass it to.

Remember this one as “number lines” (think Numberwang on Peep Show). Don’t get confused and use ln, because that is for linking files 🙂

Okay, so I’ve got a little C program, and you can view the source code on the command line with cat:

cat main.c


Very nice. Now let’s output the file with nl instead:

nl main.c


Look at that! Numbers down the side. Isn’t that handy?

But that’s not all.

Say you wanted to number all the lines – not just the ones with source code. This time use the flag -ba:

nl -ba main.c



Now let’s go a little retro, start the numbering at 10 and increase it by 10 each time (BBC Basic anyone?).

Use -v to start at your required number and -i to specify the increment:

nl -ba -v10 -i10 main.c


You can even add a string in front of each line.

Here I’ve added a colon after each number:

nl -ba -v10 -i10 -s": " main.c


The only thing missing really is the option to add disco colours and flashing text 😉

Check out the man page for full details on all the options (man nl).

A C++11 Threads Tutorial

Last week we created a simple program using the pthreads library. This week I’ve “translated” that program into the C++11 threads version, so you can see how it compares.

I say compares, but on linux, using GCC, the C++11 thread library is basically a wrapper for pthreads anyway, so although you are using native C++ commands, they are effectively calling the pthread commands that we saw last week.

So, the first thing to remember, when you are using the new C++11 thread library, is that you have to add a couple of flags to your build in order for it to run properly.

Read moreA C++11 Threads Tutorial

Fedora 21 Open Terminal From File Manager

If you use the command line a lot (like me!), then being able to switch quickly between the graphical file explorer and a terminal window in the same location is a fantastic timesaver.

On gnome this option isn’t available by default (as it is from KDE), but you can enable it by installing the nautilus-open-terminal package.

In a terminal window type:

sudo yum install nautilus-open-terminal

You may need to log out/in after doing this, although I didn’t need to on Fedora 21.

Once it has completed, if you right click in any ‘Files’ graphical window, you will see a new shortcut to ‘Open in terminal’:


Super easy and super handy too!

make: Nothing to be done for ‘all’ – Eclipse Error Solved

I’ve seen this odd error several times over the years, almost always after first importing a new project into Eclipse-CDT.

After import, when you try to build your project, it just returns the message make: Nothing to be done for all in the console.

And then, once you’ve got the error, nothing you do will kick your build into action – changing files, changing project settings, even deleting and recreating build configurations.

If you try to run the executable, you just get Launch failed. Binary not found.

Because, of course, make hasn’t built anything.


Annoying, eh?

Read moremake: Nothing to be done for ‘all’ – Eclipse Error Solved