From The Blog

MOREUTILS A MUST

There are a few tools that are not included in a base Ubuntu or Debian install that I use every day. Some are in a nice package called moreutils....

There are a few tools that are not included in a base Ubuntu or Debian install that I use every day. Some are in a nice package called moreutils.

Package description: moreutils

Description: additional unix utilities
This is a growing collection of the unix tools that nobody thought to write thirty years ago.

So far, it includes the following utilities:

  • sponge: soak up standard input and write to a file – I use this utility in bash scripts all the time.  When I am processing lots of text data I need to do things like grep for strings in a file and then replace the original file with just the data pulled from the grep.  If you were to try grep string file > file you would end up with an empty file. To get around that you could do grep string file > file.tmp ; mv file.tmp file if you wanted but spong makes it easier With sponge you can do grep string file | sponge file and the resulting file will contain the exact results of your grep.  It works by storing all the grep results in memory until the grep is finished and only then writing them down to the file.  This can simplify many tasks.
  • ifdata: get network interface info without parsing ifconfig output
  • vidir: edit a directory in your text editor – Say you have a directory full of files you want to rename in ~/Photos/ItalyTrip.   You can use vidir ~/Photos/ItalyTrip and you will get a directory listing of that folder in your default text editor.  You can then use find and replace or any other tool in the text editor to rename the files and folders.   When you exit the editor and save the changes the files and folders in ~/Photos/ItalyTrip will be renamed to match what you did in the text editor.
  • vipe: insert a text editor into a pipe
  • ts: timestamp standard input – This handy little tool will add a timestamp to data coming from standard input.  I have a series of backup scripts that run nightly and I end each script with echo “$backjob Complete” |  ts > ~/Logs/backups.log if the job finishes successfully.  By piping the echo statement through ts I get the date and times as a preface to the “Complete” statement in the log.  There are other ways to do this but this way ensures that I get the exact time and date that the job finished as opposed to when the job started.
  • 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

Homepage: http://kitenet.net/~joey/code/moreutils/

To install moreutils in any current Debian install or Ubuntu 8.04LTS or newer use:

apt-get install moreutils

Tags: