September 15, 2014

Top ten shell commands for daily use

As software writers, we spend much time reading code, writing code, browsing it, searching things on it, breaking it, fixing it, etc. All for the sake of a good behavior in a component/module we try to build.

During this process there are several opportunities in which you need something, a tool, that helps you find and do things quickly, and perhaps an IDE is an overkill when you have several things opened. So there's the shell, and with it, a lot of applications.

Normally these are the tools I most use during my daily work:
  • find - Whenever you wanna search files by name and many other options, it's mandatory.
                     $> # I'm trying to get all build reports from the projects
                     $> find /opt/projects -iname *report.html
  • grep - Excellent tool to search patterns and strings within files
                      $> # what if want to check for all logs containing the ERROR level?
                     4> grep -nHr --include="*.log" "ERROR" /opt/servers/logs/
  • tmux - Multiple SSH connections are not a problem anymore, just install tmux and create sessions within a single SSH connection.

  • tar - Mandatory tool for packaging and compressing data
                      $> tar cvfz db_dumps.tar.gz *.sql
  • watch - Lets you execute a command or script within a defined interval, helpful for monitoring things
                      $> watch -n 10 "du -hs /opt/packages"
  • xargs - Pipelines!!, who doesn't use them!? with this utility you can easily pass output data to another application
                      $> # delete all my missing files from the repo
                      $> hg missing | xargs hg rm
  • jed - Must have a simple shell editor, I prefer jed over all of them.
  • ssh - Server connections are a must have when deploying applications, learn how to use it.
  • scp - Copy files through an SSH connection without problems.
  • wget - Get those HTTP files easily, use wget.