Tuesday, July 2, 2013

Command line tips


The intention of this post is to collect a list of my favorite command line tips. Feel free to leave yours in the comment section.

  • Instead of using clear you can just press ctrl-r.
  • The command units can be used for any unit conversion you can imagine. See man page.
  • You can use multitail to monitor multiple log files on a terminal.

Sources:

Saturday, June 22, 2013

Extract decimals from text using grep

Let's say you have a log file that looks like this:
I/Profiling: TimeInterval1:  3271.72 ms
I/Profiling: TimeInterval1:  3379.15 ms
I/Profiling: TimeInterval1:  3645.32 ms
...
and you want to extract all decimal numbers so that you can get the average, or plot them. Here's how you would use grep to do this:
grep -o ' [0-9]\+\.[0-9]\+' mylogfile.log
The -o option is for just printing the matching text and not the whole line.

Friday, April 5, 2013

Simple HTTP Server in Python

A very easy way to setup a simple HTTP server is by using this built-in Python capability. This will turn any directory into a web server directory. The only thing you have to do is run:
python -m SimpleHTTPServer
on the directory you want to host the files from and that's it. You can drop an index.html file in there, for example, and hit
http://127.0.0.1:8000
in your browser and voila!