Ben Lobaugh Online

I think, therefore I am. I am, therefore I sail

Category: OS X Page 2 of 6

Find largest files in a directory using the terminal

Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity, line: 2 in /srv/users/serverpilot/apps/benlobaughnet/public/blog/wp-content/plugins/auto-amazon-links/amazon.php on line 74

If you need to find out what the largest files are in a directory and subdirectories here is a command you can run that will find the top 5 largest files.

find . -type f | sed 's/.*/"&"/' | xargs ls -Slh | head -n 5


  1. find . -type f: Find all files in this directory and below
  2. sed ‘s/.*/”&”/’: Put double quotes around the files. xargs can handle this itself, however not all implementations do, this method is safer.
  3. xargs ls -Slh: Using the filenames from 1 list them all sorted by size.
  4. head -n 5: Show the output of the first 5 rows. Which becomes the 5 largest files because ls sorted the output.

Autocomplete git branches and commands in bash

The tab completion for commands in bash is awesome, but it does not work for bash out of the box. Lucky for us it is relatively easy to get bash completion working.

You will need two things, a copy of the completion script and an update to your bash profile.

The completion script is available at:

Then in your .bashrc (or .bash_profile, or .profile, whatever you are setup for) add the following:

if [ -f ~/.bin/git-completion.bash ]; then
  . ~/.bin/git-completion.bash

Be sure the path to the git-completion.bash file is correct for your system. On mine I keep extra commands in ~/.bin.

Start using your new completion with:

source ~/.bashrc

Now simply type ‘git’ and hit tab to see all the commands available.

When switching branches type ‘git checkout’ and hit tab to see a list of the branches.

Fix “frozen” Evernote app when fullscreen on OS X

The Problem:

When you start Evernote it goes into fullscreen mode. You are not able to use any features of Evernote and hear the “Do not click me” error sound.

The Cause:

There is some sort of message box that has popped up. You need to close this before using Evernote, however it has popped up BEHIND the app and you cannot get to it.

The Resolution:

As strange as this sounds, the following steps work.

  1. Kill Evernote – If need be use the option+command+esc keystroke
  2. Disable all active network connections
  3. Re-open Evernote
  4. Switch Evernote out of fullscreen mode
  5. Close Evernote
  6. Enable network connections
  7. Open Evernote
  8. Deal with popup message

List size of directories in the current folder in terminal

If you would like to list the size of all the directories in your current folder run the following command:

du -a -h --max-depth=1 | sort -hr

This will provide output similar to

69M     .
36M     ./plugins
16M     ./.git
14M     ./themes
3.4M    ./uploads
8.0K    ./.DS_Store
4.0K    ./upgrade
4.0K    ./.revision
4.0K    ./index.php

Remove untracked local files from Git

If you have need to get rid of a bunch of files that are in your git repo but not yet tracked it can be tedious to do the job one file at a time. Git has you covered with the git clean command.

Warning: This is a permanent loss of files. Always use –dry-run to verify the action.

Remove untracked files

Remove all untracked files with

git clean -f

Remove untracked files and directories

Remove all untracked files and also any untracked directories

git clean -f -d

Page 2 of 6