Docker remove ALL volumes not attached

Docker can be tricky to debug. There’s instances where after upgrading a container the volume that was previously attached fails to work.

In this case it was a dev image and the quickest, and dirtiest, option was to clear out and rebuild. I could go one by one to delete the specific volumes.

docker volume ls
docker volume rm {specific_docker_container}

Instead I chose to delete all volumes not currently in use. This worked for my use case as I only have two dockers setups, left the one I wanted to keep running while executing the following commands.

docker volume rm `docker volume ls -q -f dangling=true`

grep without filenames

I needed to grep a directory, and sub directories, and not displaying the filenames in the output. This is when the man page came to the rescue.

man grep | grep filename


       -H, --with-filename
       -h, --no-filename

There we go, -h, –no-filename, is what I needed.

Example with output to a file:

grep -r "searching-for-this" . --no-filename > /tmp/test.txt

Vagrant error on up

I was executing a vagrant up on my machine. It was giving an nfs error.

mount -o 'vers=3,udp''/opt/<snip>/mozilla/kuma' /home/vagrant/src

Stdout from the command:

Stderr from the command:

stdin: is not a tty
mount.nfs: requested NFS version or transport protocol is not supported

I went hunting for a resolution. I need to install nfs libs.

sudo apt-get install nfs-common nfs-kernel-server

Then it would boot.

Simple Python Web Scraper

I needed a simple html only scraper. (This doesn’t use js, won’t pull down data via AJAX). I found an example on another site,, but it wasn’t exactly what I needed. It only pulled the data and printed it to screen. I added a list to loop through and auto saving by url name to a html file.

import mechanize  #pip install mechanize

br = mechanize.Browser()
br.addheaders = [(&quot;User-agent&quot;,&quot;Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13&quot;)]

sign_in =;;)  #the login url

br.select_form(nr = 0) #accessing form by their index. Since we have only one form in this example, nr =0.
#br.select_form(name = &quot;form name&quot;) Alternatively you may use this instead of the above line if your form has name attribute available.

br[&quot;email&quot;] = &quot;email or username&quot; #the key &quot;username&quot; is the variable that takes the username/email value

br[&quot;password&quot;] = &quot;password&quot;    #the key &quot;password&quot; is the variable that takes the password value

logged_in = br.submit()   #submitting the login credentials

logincheck =  #reading the page body that is redirected after successful login

urls = [&quot;;,&quot;;]

for url in urls:
	req =
	filename = url.split('/')[-1] + &quot;.html&quot;
	f = open(filename, 'w')

Which produces 2 files:

How to check cp progress after cp has started

First, the easier way to do this is to use rsync in the first place.

rsync -avh –progress sourceDirectory destinationDirectory

However, sometime you think cp will be quick and you already kicked it off. Here is a quick way to check the progress of a copy command after you’ve already started.

watch lsof -p`pgrep -x cp`

This will let you know what it is transferring and how much it has left to do. In a way it provides a way to check the progress of the cp, copy comand.

To find out more check out these two SO links:

Check progress

CP Command Help

Ubuntu Command line Display Driver Change

Recently upgraded to 15.10 and that looked okay at first. However, the displa driver that it installed, NVIDIA, was causing issues. So I defaulted back to the open source driver and reboot. MISTAKE! Ended up causing the system to crash and couldn’t do anything about it.

I rebooted into root terminal. Then ran a command to display the available drivers.

ubuntu-drivers devices

The spit out a list of drivers. Then I reinstalled the latest available nvidia driver.

apt-get install nvidia-352-updates

Failed to spawn command gulp

I ran in to the error with Atom, Failed to spawn command gulp. The solution for me was to install the module globally.

$ sudo npm install -g gulp
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
[email protected] /usr/lib/node_modules/gulp
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Easy and done.

Bash test if file exists

Using bash I needed to check that a file exists, then do something. This one turns out to be super simple. I wanted to conditionally load a db file if it existed in this case.

What I needed was, a check for the file in bash. Then execute the command. In this instance it was to load a postgres restore file.

[ -f $db_dump ] && printf "Loading DB...\n";sudo su postgres -c "pg_restore -d db_name_here $db_dump;" || printf "No db dump to load\n"

Another way to write this is to use a full if/else conditional. Admittedly this is a little cleaner.

if [ -f "$db_dump" ]
	printf "Loading DB...\n";
        sudo su postgres -c "pg_restore -d db_name_here $db_dump;"
	printf "No DB file found.\n";