Skip to content

Entries tagged "bash".

Load a directory in RAM

A nifty little bash script that loads stuff in memory so it runs super fast!
#!/bin/bash
#
# This script remounts a directory in tmpfs (ramdisk) to speed it up
#

DIR=$1
SIZE=$2

if [ ! "$UID" = "0" ]; then
    # this script must run by root. Let's try sudo'ing to root..
    exec sudo $0 $*
fi

if [ ! -d $DIR ]; then
    echo "Usage: $0 "
    exit 1
fi

if [ "a$SIZE" = "a" ]; then
    OPTIONS=""
else
    OPTIONS="-o size=$SIZE"
fi

# first, copy everything somewhere to reuse it later
TMP=`mktemp`
tar cpf $TMP $DIR

# remount dir as ramdisk
mount -t tmpfs $OPTIONS $DIR $DIR

# unpack everything back
(cd / && tar xpf $TMP)
rm -f $TMP
Cheers Evgueni!

grep: Argument list too long

A quick one.
Today I tried grepping for some stuff in a large Maildir and received the aforementioned error.
A nice workaround is to use:
grep -r "blah blah" /path/to/dir
instead of
grep "blah blah" /path/to/dir/*


HTH!