Alternative to cd ../../../../

Posted on August 30, 2009

up 4

Sometimes when working on the console you go deep in the directory structure, so when you have to go back you are forced to type a lot, I know you could do a cd -, but assume that the last directory you were in is not where you want to go.
Follows the script, credit goes to this guy who posted the script in this thread. I slightly changed the code to provide the same functionality of up 1 when one just types up.

  1. up(){
  2. limit=$1
  3. for ((i=1 ; i <= limit ; i++))
  4. do
  5. d=$d/..
  6. done
  7. if [ -z "$d" ]; then
  8. d=..
  9. fi
  10. cd $d
  11. }


Get the source code here.

Browse the archive

blog comments powered by Disqus