4 ms·
I wrote a bash function yesterday which allows you to cd ... to move up two directories instead of having to cd ../.. Want to move up 4 directories?
by sant0sk1 17y ago
I wrote a bash function yesterday which allows you to
cd ...
to move up two directories instead of having to
cd ../..
Want to move up 4 directories?
cd .....
Pretty useful, imo. Check it out
http://blog.jerodsanto.net/2009/09/cd-up-up-up/ http://blog.jerodsanto.net/2009/09/cd-up-up-up/
- bachya 17y agoCan't remember where I found this, but this function allows you to go up any level of dirs without specifying an infinite number of aliases. Usage: up {x} where x is the number of directories you want to go up (e.g., 3) function up() { local arg=${1:-1} local dir="" while [ $arg -gt 0 ]; do dir="../$dir" arg=$(($arg - 1)); done cd $dir >&/dev/null }
- gcv 17y agoIn zsh, you (1) don't need to write a function, and (2) you don't need to type "cd" to switch directories. setopt auto_cd alias -g ...='../..' alias -g ....='../../..' alias -g .....='../../../..' alias -g ......='../../../../..' Then you can just type "..." and go up two directory levels, and so on.
- sant0sk1 17y agoThat's pretty cool. I've shied away from zsh for some time as I'm very comfortable with bash, but a lot of evidence has been coming to me lately that makes me want to give it a go.
- mcxx 17y agoI have just an alias for this (without the cd) in my ~/.bashrc: alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../../'
- sant0sk1 17y agoYah that's a nice way to fix it as well, but I prefer to be able to continue using the "cd" command since it is burned into my brain.