Skip to content

Instantly share code, notes, and snippets.

@turbotobias
Created June 7, 2023 23:03
Show Gist options
  • Select an option

  • Save turbotobias/5f032ec7b811cf136ac5a65fb3ac05cd to your computer and use it in GitHub Desktop.

Select an option

Save turbotobias/5f032ec7b811cf136ac5a65fb3ac05cd to your computer and use it in GitHub Desktop.
Change directory to many parents shorthand
# change directory to any parent
# instead of writing "cd ../" you can write:
# $ u
# instead of writing "cd ../../" you can write:
# $ u 2
# instead of writing "cd ../../../../../../../../../../" you can write:
# $ u 10
function u() {
if [[ "$1" =~ ^[0-9]+$ ]]; then
local dir=""
for ((i=0; i<$1; i++)); do
dir="../$dir"
done
cd $dir
else
echo "Usage: u N"
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment