Environmental issues (part 2)


When working a lot with command line utilities, I usually find myself retyping certain commands. This fact is a good reason for someone to use aliases to save typing time and errors.

At first we have to check our most loved/typed commands. This can be done using:

history | cut -c 8- | sort | uniq -c | sort -nr | head -20

in order to show the 20 most frequently used [1]. Of course, the above commands combination must be an alias too [2].

After analyzing the output, we can decide which commands could be substituted by aliases, insert them in the ~/.alias file and use them after we “source” it [3].

[1] Explanation of the commands used:

  • history: show the last commands entered
  • cut -c 8-: cut the first 7 characters from each line of “history” output (cut off the number)
  • sort: sort the commands alphabetically
  • uniq -c: count same commands in a frequency table
  • sort -nr: sort the frequency table by descending counts
  • head -20: show only the first 20 lines

[2] alias hist_top20=’history | cut -c 8- | sort | uniq -c | sort -nr | head -20′ >> ~/.alias
[3] after editing ~/.alias, `source ~/.alias`

Visit The Light of the LAMP blog for more…