Pages

Thursday, January 1, 2015

..(), go up in directory tree, func to long please refer to description

$ [ ~/temp/foo/bar/baz ] $ .. 3

many have aliases like:


alias ...="cd ../../"


alias ....="cd ../../../"


and so furth.


..() mitigates to need for those aliases, see sample output for an example


# .. -> go up 1 directory


# .. 4 -> go up 4 directories


..()


{


local DIR=''


declare -i NUM=0


if [[ ${1} =~ ^[1-9][0-9]*$ ]]


then


while (( ${NUM} < ${1:-1} ))


do


DIR="${DIR}../"


NUM=$(( ${NUM} + 1 ))


done


else


DIR=..


fi


cd "${DIR}"


}




commandlinefu.com


by David Winterbottom (codeinthehole.com)






from All commands http://ift.tt/1xyg3Zv

No comments:

Post a Comment