Category: Command line Fu

  • How to randomly sample k lines from a file in *nix

    You can use the shell to extract a random sample of lines from a file in *nix. The two commands you need are “shuf” and “head” (+ “tail” for CSV files with a header). The shuf command will randomly shuffle all the lines of its input. The head command will cut of the input after […]

  • Log devices on your network

    Fing logger ( #!/bin/sh FING_LOG_FILE=/path/to/fing.log # append current public ip echo `date +”%Y/%m/%d %T”`”;publicip;”`curl -s`”;;;” >> $FING_LOG_FILE # append current fing output /usr/bin/fing -r1 -o log,csv,$FING_LOG_FILE,1000 –silent Add to cron (run every hour): 0 * * * * /path/to/

  • Which files has a *nix process opened?

    To list all files that are opened by a *nix process with a given pid, say 42, use the lsof command: (sudo) lsof -p 42 Of course, a process may have many files open. To list only files that have a name containing “log”, use the grep command: (sudo) lsof -p 42 | grep log […]

  • Docker on Ubuntu VM running on Mac using Vagrant

    Docker allows you to develop, ship and run any application, anywhere. The metaphor is that of the standard shipping container that fits on any ship, can be handled by any crane, and loaded onto any train or truck. In a previous post, I covered how to run Ubuntu on Mac using Vagrant. In this post, […]

  • Running Ubuntu on Mac with Vagrant

    Vagrant is cool: Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team. Furthermore: Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, […]

  • Starting a web server and other PHP tricks

    Start PHP webserver (in current directory): php -S localhost:8080 # starts http server on port 8080 Start PHP prompt (with illustrating example):

  • Easiest way to install a PostgreSQL/PostGIS database on Mac

    Installing Postgres+PostGIS has never been easier on Mac. In fact, it is now an app! You download the app-file from, place it in your Applications folder, and you’re done. Really. If you think that was over too fast If you think that was over too fast, there is one more thing you can do. […]

  • Poor man’s wget

    The command wget is useful, but unfortunately doesn’t come preinstalled with Mac. Yeah, you can install it of course, but if you’re doing it from source, the process has a few steps to satisfy all the dependencies; start by configure make’ing the wget source and work your was backwards until ./configure runs for your wget […]

  • How to set environment variables for single process

    In bash, you simply prefix a command with one or more XXX=”YYY” pairs, e.g. $ A=”B” X=”Y” python … A=B X=Y The code for import os for ev in os.environ: print “{0}={1}”.format(ev, os.environ[ev])

  • Playing with GraphViz and MathGenealogy data

    Math in Genealogy is a great project (donate online). Sven Köhler from Potsdam, Germany has written a python script for visualizing the database, which I’m going to try. First step is to clone the git repo: $ git clone His instructions are quite simple: $ ./ –search 38586 # 30 seconds $ ./ –display […]

1 2 3 5
Next Page