August 17, 2014

Up!

Like many other scripts, the bash shell function "up" is a by product of my laziness. As the name vaguely indicates, it can move you up in the directory tree. If you want to move 3 levels up in the directory tree, you invoke the function as up 3 instead of cd ../../../  which saves a ton of typing. The shell function can be downloaded from my GitHub repo. 

# Go n level up in the directory structure.
# License : GPLv3
function up ()
{
        lvls=""
        if [[ ! -z "$1" ]]
        then
                for i in `seq $1`
                do
                        lvls="${lvls}../"
                done
        else
                lvls="../"
        fi

        # Will land up in / if n is too large.
        cd ${lvls}
        pwd
}


The ShellUtils repo contains few other shell scripts that might be interesting. See the Readme file in the repo to find out what those scripts are doing.

No comments:

Post a Comment