Securely deleting files

I needed to switch cellphones, and given that my cell’s SD card had sensitive data, just formatting the card wasn’t sufficient — it’s trivial to recover files from high-level-formatted FAT file system.

I present to you the world’s most dangerous (unix) command:

 find /path/to/mounted/SDcard -type f -print0 | xargs -0 shred -z -u

(shred is part of the coreutils package, so it should be installed already)

HOWTO: simulate the cron environment

While banging my head on RVM + Rails 3 + crontabs, it became clear that I needed the cron environment in an interactive shell. It’s not hard:

sudo su
env -i /bin/sh

If your SHELL in your crontab is /bin/bash:

sudo su
env -i /bin/bash --noprofile --norc

Remember that the cron-invoked shell won’t have a tty, so some commands will behave differently. Also, if you’ve got a bunch of other environment variables set up in your crontab, you can do this trick from stackoverflow — create a one-off cron that writes env to a file, and load that env later.

HOWTO: Mount your USB hard drives at boot time on Ubuntu

I’ve got a number of external USB hard drives connected to my ubuntu server that need to mount to a predictable directory.

When you log into Gnome, the desktop environment does it’s nifty thing and mounts any drive you’ve got plugged in — but if the box reboots, the drives won’t be mounted until the next person logs into the computer.

I needed something that happens at boot time to do this task.

Continue reading

Set up JAVA_HOME to track Java Preferences.app on Mac OS X

/Applications/Utilities/Java Preferences.appMac OS X’s Java Preferences.app has a pane for switching between versions of the JDK, but I just found out from a coworker (thanks, Mike!) that you can make your shell match that preference easily — just add this to your ~.bashrc:

export JAVA_HOME=$(/usr/libexec/java_home)

If you change your JDK priority preference, you’ll need to re-source your ~/.bashrc or just open a new terminal window.

Make “ps -ef” work in a shell on Mac OS X

If you’re used to SunOS or BSD, you’ll be at home with Mac OS X’s “ps -aux” to get a process list from a shell prompt.

If you’ve been using any other recent unix, though, your fingers will want to type ps -ef instead. Rather than hack an alias to wrap ps to make this happen, it turns out there’s an easy way to return to the ps promised lands.

By default on Mac OS X 10.5.2, the shell environment’s COMMAND_MODE is set to legacy. If you set it to unix2003, you’ll get your ps -ef. Just add

export COMMAND_MODE=unix2003
alias zcat='gunzip -c'

to your ~/.bashrc to make it be set automatically.

The alias of zcat to gunzip -c fixes a “feature” in unix2003 mode — it removes gzip support from zcat. If you’re used to using zcat for both compressed .Z files as well as gzipped .gz files, you want the alias line as a workaround.

Ant bash completion on Mac OS X

bash will do tab-completion for ant targets on Debian/Ubuntu boxes out-of-the-box. If you haven’t upgraded lately, you may need to:

sudo apt-get install bash-completion

On Mac OS X, it needs a bit of massaging. First install the macports version of bash-completion and ant:

sudo port install bash-completion apache-ant

Then add this to the end of your ~/.bashrc:

if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
complete -C /opt/local/share/java/apache-ant/bin/complete-ant-cmd.pl ant

See http://marius.scurtescu.com/2005/03/23/ant_bash_completion for Windows instructions.