Created
June 7, 2023 23:03
-
-
Save turbotobias/5f032ec7b811cf136ac5a65fb3ac05cd to your computer and use it in GitHub Desktop.
Change directory to many parents shorthand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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