10

Tip #550   Go up n directory levels

You often see people using aliases like "alias ..='cd ..'" and "alias ...='cd ../..'". Here is a general version of this kind of '..' command, which takes an argument for how many levels up to go.

# .. - Does a 'cd ..'
# .. 3 - Does a 'cd ../../..'
#
function .. (){
  local arg=${1:-1};
  while [ $arg -gt 0 ]; do
    cd .. >&/dev/null;
    arg=$(($arg - 1));
  done
}

 
  • TAGS:
  • cd