Unix Commands to Try When You're Bored

By Sandra Henry-Stocker  2 comments

Not every Unix command sparks with novelty. After all, the OS has now been around for roughly forty years and the spark wears off. But there are some commands that pick up from where the basics run out of steam. Jump on a Linux box and try these out when you have a little free time. You might surprise yourself with some new tricks for your bag of Unix goodies.

Before we get started with the commands you may not have heard of before, here's a tired and true Unix command that we've all been using for decades, but maybe not this particular way. This grep command represents the simplest way to remove blanks lines from a file that I've ever seen.

grep . oldfile > newfile

Got that? It matches any lines with anything (i.e., not nothing) in them and tosses them into the second file. Hey, this is even easier than my old "grep -v ^$ oldfile > newfile" command that would specifically omit empty lines from the new file.

Now let's look at a command you might not have come across before. The comm command (think of "comm" as in "common" to be contrasted with "diff" as in "difference"). The comm command will attempt to display the lines that two files have in common. Here's an example:

$ cat file1
Remember when we were poor?
No.
Me neither.
The end.

$ cat file2
Let's slip a coin!
Flip what?
The end.

$ comm file1 file2
        Let's slip a coin!
        Flip what?
Remember when we were poor?
No.
Me neither.
                The end.

Pay attention to the way the output is indexed. The lines up against the left side of your screen are those that appear only in the first file. The lines in the middle column appear only in the second file. The lines in the rightmost column are those that appear in both files. In similar manner to diff, the ordering of the lines makes a big difference in how the command operates. If the files aren't sorted, comm will only find the first set of matching lines. Any additional matches will be ignored. Let's look at another example and see this in practice.

Let's say we have a file containing the letters a, b, c, x, a, b, c (one per line) and another containiny a, b, c, x, a, b, c. The comm command will only detect the first match.

$ comm file5 file6
                a
                b
                c
        f
        a
        b
        c
x
a
b
c

Like diff, the comm commands has some other options (like selecting whether to see only some of this output). Read the man page.

Another interesting command is called "tac". Yes, that's "cat" spelled backwards. And what would you expect such a command to do? It displays a file in reverse order -- upside down. So, our a, b, c, x, a, b, c file shows as:

$ tac myfile
c
b
a
x
c
b
a

Another interesting command is called "links", homonym for "lynx" and a command with a similar purpose in life. Like lynx, it's a test-based web browser. It lets you scroll up and down the page you direct it to, supports frames and is a generally easy to use and friendly tool.

Last on our list for today is "locate" with features in common with the which and find commands. The locate command pulls information about the files it finds from a prepared database, so it's quick. Do a locate on perl and you'll find the command, man pages, modules and who knows what else. When you don't have time to wait for a find command to complete, you might find what you're looking for very quickly with locate.

Nice commands from a operating system that hasn't lost its spark.

See other Unix tips here.

ITworld LIVE

Operating SystemsWhite Papers & Webcasts

White Paper

A Comparison of PowerVM and VMware vSphere (4.1 & 5.0) Virtualization Performance

This technical white paper presents benchmark results showing greater VM consolidation ratios than demonstrated in previous benchmarks and demonstrating the extent of the performance lead that PowerVM virtualization technologies deliver over x86-based add-on virtualization products.

White Paper

Consolidating Lotus Domino x86 Workloads on IBM Power Systems

Read the white paper to learn how moving up to Lotus Domino 8.5 and consolidating with IBM Power Servers can help you boost performance results and ROI.

White Paper

Task, workflow & issue management for teams. Try free!

Need a flexible system for managing team tasks, issue tracking, and automating and managing workflow processes? Comindware® Tracker helps you do it all.

Webcast On Demand

Best Practices in Monitoring VMware

The benefits of virtualization are unassailable: increased agility, scale, and cost savings to name a few. However, so too are the monitoring challenges posed by these environments-including complexities, lack of visibility and control, and inefficiency.

Sponsor: Nimsoft

White Paper

How Nimsoft Service Desk Speeds Deployment and Time to Value

For years, many support teams have been hamstrung by their traditional service desk platforms, which require complex, time-consuming coding for virtually every aspect of customization. This complexity makes it costly and difficult for support organizations to adapt-and places an increasingly substantial burden on the agility and efficiency of the business as a whole.

See more White Papers | Webcasts

Ask a question

Ask a Question