Some bashrc shorcuts for faster and profiecient directory browsing.

2010-03-10 196 words 1 min read

Here are some of the funtions that I have in my bashrc to make my life simple. They are not written by me but mostly taken from other places, but modified by me to some extent to suit my needs. If you know the original creator of these, let me know so I can add the attribution for the same.

This one is very useful.

.. (){
local arg=${1:-1};
local dir=””
while [ $arg -gt 0 ]; do
dir=”../$dir”
arg=$(($arg – 1));
done
cd $dir >&/dev/null
}

Another very useful function:

up ()
{
[[ $# == 1 ]] && a=$1 || ([[ $# == 0 ]] && a=1 || echo ”Enter only one or zero parameter” )
echo ”Moving up $a dirctories…”
for (( i=0; i<$a ; i++ ))
do
builtin cd ..
echo &#8221;Up one directory to $(pwd) .. &#8221;

done
ls
}

If those 2 do not meet your requirement then add this too 🙂

… (){
if [ -z &#8221;$1&#8221; ]; then
return
fi
local maxlvl=16
local dir=$1
while [ $maxlvl -gt 0 ]; do
dir=&#8221;../$dir&#8221;
maxlvl=$(($maxlvl – 1));
if [ -d &#8221;$dir&#8221; ]; then
cd $dir >&/dev/null
fi
done
}

[[danscartoon]]


Tags: bash tips

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it