Wednesday, 3 June 2009

Getting more done with moreutils

I was introduced to moreutils a few weeks ago and I now wonder how I managed without it. Installing is straight forward enough:

sudo apt-get install moreutils

This adds the following commands:

- sponge: soak up standard input and write to a file
- ifdata: get network interface info without parsing ifconfig output
- ifne: run a program if the standard input is not empty
- vidir: edit a directory in your text editor
- vipe: insert a text editor into a pipe
- ts: timestamp standard input
- combine: combine the lines in two files using boolean operations
- pee: tee standard input to pipes
- zrun: automatically uncompress arguments to command
- mispipe: pipe two commands, returning the exit status of the first
- isutf8: check if a file or standard input is utf-8
- lckdo: execute a program with a lock held

sponge is particularly useful:

sort file.txt | sponge file.txt # sort file.txt and dump it back to file.txt without clobbering the file.

The vipe command is a useful way to edit data in a pipeline, especially if you cannot be bothered to figure out smart sed logic to edit data in the pipeline.

I've found ts useful for capturing data out of a log and time stamping it - kind of handy for debugging purposes.

vidir is great for editing filenames in a directory, but can be a little too powerful in my opinion as one can really screw up a load of files if one is not careful!

No comments:

Post a Comment