Linux - grouping commands in parentheses, aliases

One other Unix command while I'm in the neighborhood. Somewhat along the lines of what I was doing on Monday -- looking at the size of Apache log files -- I wanted to generate a sorted list of log files for May and June only. Here's how to solve that problem by grouping Unix commands:

(may;jun) | sort +4n

In this example, I'm grouping the commands 'may' and 'jun' together using the parentheses, and piping their combined output into the sort command. With the sort command, I'm sorting numerically by the 5th column.

It doesn't matter too much, but 'may' and 'jun' are actually aliases, and are defined like this:

alias may="ls -al | grep May | grep -v 2002"
alias jun="ls -al | grep Jun | grep -v 2002"

I hope some of that makes sense. The most important thing I was trying to show was the grouping of commands using the parentheses.

 

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.