Sunday, March 29, 2015

find large files with BASH

Recursively searches from current directory reporting the location and count of all files greater than the specified size. Add it to the .bashrc file for an easy find tool.

Example usage is 
  findlargest
  findlargest 5M
  findlargest 1G

defaults to 50Mb

function findlargest_inner { 
  eval "find . type f -size +${1:-50M} -exec ls -lh {} \;" \
  2>&1 | \
  grep -v "Permission denied" | \
  awk '{ print $9 ": " $5 }' | \
  grep -v -e '^:.*';
}

function findlargest {
  findlargest_inner $@
  echo "Number of files found with size>${1:-50M} is :"
  findlargest_inner $@ | wc -l
}

Sunday, February 22, 2015

nmap vs brew on osx

So recently I tried installing nmap primarily for discovering a lazy way of controlling Minecraft on our Raspberry Pi over the home LAN.

Naturally it didn't work first time.
Naturally I spent hours trawling stack overflow and the only matches for my error messages were about  Ruby, which had nothing to do with what I wanted.

Finally found the solution that worked, its here:

The error:
~:-> nmap
dyld: Library not loaded: @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/bin/nmap
  Reason: image not found
Identify the problem:
  ~ : ->otool -L /usr/local/bin/nmap
/usr/local/bin/nmap:
        /usr/lib/libpcap.A.dylib (compatibility version 1.0.0, current version 1.0.0)
        @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
 @@HOMEBREW_PREFIX@@/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)

        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
Now to correct the two HOMEBREW_PREFIX paths:
~ : ->sudo install_name_tool -change @@HOMEBREW_PREFIX@@/opt/openssl/lib/libssl.1.0.0.dylib/usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/bin/nmap
~ : ->sudo install_name_tool -change @@HOMEBREW_PREFIX@@/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/bin/nmap
Then run otool again, and the homebrew_prefix variables should have been replaced with absolute paths. This fixed nmap for me!

Also useful, but not *the* fix:
brew --config
brew doctor
brew update
This link was the one that helped the most
http://superuser.com/questions/282450/where-do-i-set-dyld-library-path-on-mac-os-x-and-is-it-a-good-idea