Sunday, 13 April 2014

moreutils - a collection of useful UNIX tools

'moreutils' is a fantastic general purpose collection of useful UNIX tools. It was developed to be additional go to command line tools.


  • Install on Ubuntu or Linux Mint 

$ sudo apt-get install -y moreutils

ifdata - quickly gather network data

  • Quick way view network information without grep's of ifconfig
  • Print interface information
 $ ifdata -p eth0 1500

  •  Reports interface existence via return code
$ ifdata -e eth1 && echo "Eth1 exists" || echo "No Eth1"
No Eth1

  • It has many other options and is really useful for scripts
  ts - timestamp input

  • Adds a timestamp to the beginning of each line of input
  • Useful for data gathering or backup scripts
  • Example to gather disk usage
$ df -h /home/ | ts > disk.tmp
$ cat disk.tmp
Jun 15 16:52:10 Filesystem      Size  Used Avail Use% Mounted on
Jun 15 16:52:10 /dev/sda7       183G   33G  141G  20% /home

vidir edit directory contents in a text editor
  • If no directory is specified teh current directory is used
  • Each item in the directory will appear on its own numbered line
  • Delete lines to remove files from the directory
  • Edit filenames to rename files
$ vidir experimental/

sponge - allows pipes that read from and write to the same file
  • Reads standard input and writes it out to the same file
  • If you grep for a value and try to write back to the same file it will wipe out the file

$ grep Complete backup > backup
grep: input file ‘backup’ is also the output
$ cat backup

  • Using sponge avoids having to create temporary files
$ grep Complete backup | sponge backup
$ cat backup
Jun 15 16:50:25 “Complete”

  •  The grep results are stored in memory before being written back to the file

No comments:

Post a Comment