Code and comments

Practical and theoretical aspects of software development

Posts Tagged ‘linux

Using find and grep.

leave a comment »

Back in August of last year, for one of the first posts on my brand-new blog, I put up the slides from a lunch-time presentation that I gave on find, grep, sed, and awk. I put it up so that it would be available as reference to those that attended the talk, even though the slides weren’t designed for stand-alone use, and slides make a poor Internet reference.

Given the surprising popularity of that post, it seemed reasonable to repackage the information in a format that is more fitting for a blog post.

find and grep are incredibly powerful. But many never learn a fraction of what they can do. Did you know that grep can print the surrounding lines? Or that you can search for files based on permissions? Here’s a collection of examples that might expand your notion of what can be done with find and grep.

Read the rest of this entry »

Advertisements

Written by Eric Wilson

January 31, 2012 at 12:15 pm

Posted in how-to

Tagged with , , ,

Command-line keyboard shortcuts for Bash

with 3 comments

I love keyboard shortcuts, and I do my best to incorporate them with every GUI application that I use regularly. I’ve been comparatively negligent in learning keyboard shortcut for the command-line applications, as it seems less advantages. After all, there’s no need to reach for the mouse, what are we hoping to save?

Nevertheless, there are real efficiencies out there, and here are my favorite Bash shortcuts. Read the rest of this entry »

Written by Eric Wilson

October 25, 2011 at 5:39 am

Posted in how-to

Tagged with , , ,

Viewing multiple files with less

leave a comment »

When you want to see the contents of a text file in unix, the first two things to come to mind are cat and less. I choose cat when the files are small, but the pagination and navigation in less makes it the better choice most of the time.

Suppose you find a directory with five files that are unknown to you. Printing the contents of all five is easy enough with cat and a pipe:

$ ls | xargs cat

 
But if you have five files, chances are you don’t just want everything scrolling past you. So we try:

$ ls | xargs less

 
Hmm … when you get to the bottom of file1.txt we find the message (END) - Next: file2.txt. What to do?

As always, the answer is in the man page: :n for next file, :p for previous file.

Of course, this isn’t only useful when piping input into less, it also works when specifying multiple arguments:

$ less file1.txt file2.txt file3.txt

 

Written by Eric Wilson

October 17, 2011 at 2:26 pm

Posted in how-to

Tagged with , ,

Getting started with The Little Schemer

with 4 comments

Every programmer should read The Little Schemer (pdf) at some point. It doesn’t take long to read, and I hope to provide a review of it soon. For now, I hope to explain how to get started practically with Scheme, as used in this book, since these details are hard to find.

Read the rest of this entry »

Written by Eric Wilson

September 1, 2011 at 9:52 am

Posted in how-to

Tagged with , , ,