$ cd a/b/c/d/e/fThat is, typing all that ../../../../.. Even just "cd .." seems like a lot of characters to type for such a common task.
$ ./some-cmd
$ cd ../../../../..
So years ago I created a shell function called up to handle cd-ing up the directory tree. If you use up with no arguments, it cds up one directory. But you can also tell it how many directories to cd up, which is where its power comes in. The above example becomes:
$ cd a/b/c/d/e/fThe shell function code is below. It works for bash and zsh, and it only uses shell builtins. I put this code in my .bashrc and .zshrc files.
$ ./some-cmd
$ up 5
function up()A little explanation... The printf creates a string of N zeros, where N is the number of directories to cd up. The cd line uses the ${parameter/pattern/string} expansion to turn each "0" into a "../".
{
if [[ -z $1 ]]; then
cd ..
else
if [[ $1 =~ [0-9]+ ]]; then
local U=$(printf "%0${1}d" 0)
cd ${U//0/'../'}
else
echo up: bad arg
fi
fi
}
p.s. Yes, I know that pushd/popd solves the same problem, but I never got used to those. Also, I frequently cd down five directories, but then want to go up two. So for me, up is more versatile.