Is there any shortcut for cd ..?

link|improve this question

50% accept rate
42  
Does it take so long to type? – WTP Mar 19 '11 at 15:08
15  
YES, it does take too long for something needed that often. – maaartinus Mar 19 '11 at 16:08
2  
Try push and pop – Dr. Zim Mar 19 '11 at 19:44
16  
I'm terribly amused that someone finds cd .. too cumbersome to type – Erik Mar 20 '11 at 8:16
5  
I suspect the people who need ‘cd ..’ so often have the “I must cd into a directory before talking about the files there” anti-pattern, rather than specifying filesystem paths. – bignose Apr 20 '11 at 7:08
show 5 more comments
feedback

9 Answers

up vote 58 down vote accepted

Not by default (There might be some exceptions to this), there isn't. But if you use the alias command you can create a shortcut like this:

alias ..="cd .."

This will allow you to use the command .. to do cd ...

link|improve this answer
9  
Damn, I was just typing the exact same thing. – Majenko Mar 19 '11 at 15:10
6  
I'm using also alias ...="cd ../.." and two more. Additionally, I can recommend alias ,=cd "$OLDPWD". – maaartinus Mar 19 '11 at 16:09
12  
@maaartinus: cd -. – honk Mar 19 '11 at 16:11
1  
@honk I didn't know it. However, it's too long (and I don't need the output). – maaartinus Mar 19 '11 at 16:25
1  
Could someone please explain the downvote? – Wuffers Mar 19 '11 at 22:24
show 5 more comments
feedback

Activate the autocd option. It will let you type .. for cd .. and will actually let you use any directory as a command name and will cd to it:

shopt -s autocd

For the curious, the same exists for zsh:

setopt auto_cd
link|improve this answer
1  
That is fantastic. Time to edit .bashrc on all my linux boxes. Unfortunately it doesn't seem to work with cygwin bash. – gordoco Mar 19 '11 at 19:42
2  
Woah, that's awesome. – Reid Mar 19 '11 at 20:38
4  
@gordoco: yeah, it's bash 4.x only. It's the reason why I've been using zsh for 14 years. – Sam Hocevar Mar 20 '11 at 1:55
1  
zsh (+ auto_cd) FTW! – Johnsyweb Mar 20 '11 at 3:17
That's odd, I'm running bash and shopt -s autocd doesn't work. Any ideas why? – Wuffers Mar 20 '11 at 14:11
show 5 more comments
feedback

I find this useful:

up() { local p= i=${1:-1}; while (( i-- )); do p+=../; done; cd "$p$2" && pwd; }

For example, up 4 = cd ../../../..

link|improve this answer
That's interesting! In 2007 I wrote a similar [function] (home.arcor.de/hirnstrom/minis/index.html#up_X) for my .bashrc - file. Your solution allows to jump back the whole way with cd - too. Well done! :) – user unknown Mar 20 '11 at 8:57
feedback

I use this one since I type too fast and often miss the space bar:

alias cd..="cd .."
link|improve this answer
Most inconvenient for a non-unix person occasionally on a *nix box +1 – mplungjan Mar 19 '11 at 17:52
9  
s/non-unix/Windows/ – grawity Mar 19 '11 at 19:02
3  
If you are typing so fast you are missing characters, it's hard to believe adding alias for cd.. really helps. – Olli Mar 20 '11 at 12:25
1  
I can see how it could help if you come from dear old DOS, where cd.. was valid :) – cambraca Mar 20 '11 at 19:02
1  
For some reason I have been typing cd.. a lot for the past week. I thought I was going to have to quit coffee but I like this solution way better. – Syntax Error Mar 20 '11 at 20:35
feedback

After doing a

bind '"\eu":"cd ..\C-m"'

you can cd .. by pressing Alt-u. I used to use this on chdir championships ;-)

If you want the whole swift-chdir suite

ALT+u cd ..
ALT+n enter next dir for selection
ALT+p enter previous dir for selection
ALT+SPC choose selected dir
ALT+l list subdirectories and highlight selection

just include this in your .bashrc

swiftcd-status() {
    echo -n -e "\r\0033[1A\0033[J"
}

swiftcd-contents() {
    find "$swiftcdpath" -maxdepth 1 -executable -type d
}

swiftcd-setdir () 
{ 
    swiftcdpath=$PWD
    swiftcddirnum=1
    swiftcddircount=`swiftcd-contents|wc -l`;
    swiftcd-status
}

swiftcd-pd () 
{ 
    (( --swiftcddirnum <= 0 )) && swiftcddirnum=$swiftcddircount;
    swiftcd-switch $swiftcddirnum
    swiftcd-status
}

swiftcd-updir () 
{ 
    cd ..;
    swiftcd-setdir
}

swiftcd-list () 
{ 
    local redOn="$(echo -e '\0033[31m\0033[1m')"
    local redOff="$(echo -e '\0033[m')"

    swiftcd-status
    ((  swiftcddircount > 1 )) && { 
        echo
        echo $(swiftcd-contents|sed 's!^'"$swiftcdpath"'!!'|sed $swiftcddirnum' s/\(.*\)/'"$redOn"'\1'"$redOff"'/')
    } 
}

swiftcd-nd () 
{ 
    (( ++swiftcddirnum > swiftcddircount )) && swiftcddirnum=1;
    swiftcd-switch $swiftcddirnum
    swiftcd-status
}

swiftcd-switch() {
    (( $1 <= swiftcddircount && $1 > 0 )) && cd $(swiftcd-contents|sed -n $1' p')
}

bind '"\e ":"swiftcd-setdir\C-m"'
bind '"\ep":"swiftcd-pd\C-m"'
bind '"\eu":"swiftcd-updir\C-m"'
bind '"\en":"swiftcd-nd\C-m"'
bind '"\el":"swiftcd-list\C-m"'
swiftcd-setdir
link|improve this answer
4  
What's a chdir championship? ignorant – Peter Jaric Mar 19 '11 at 21:57
3  
Directory navigation sports event. – artistoex Mar 19 '11 at 22:11
Thanks! a little less ignorant – Peter Jaric Mar 21 '11 at 9:35
@Peter You're welcome ;-) – artistoex Mar 21 '11 at 12:22
feedback

Try autojump: autojump on github

This will not only shorten the cd command into 'j' but also shorten the characters needed for typing the folder you want to jump into.

If you always cd into the folder /home/foo/Projects/thenextfacebook you can just do 'j face' and there you are. It learns automatically which folders are the most important ones for you and after using it for a month now I can say that it is very accurate.

link|improve this answer
feedback

My bashrc file contains

alias ..="cd .. && ls -lG"

as well as

alias ,,="pushd .. && ls -lG"
link|improve this answer
feedback

Try Cd Deluxe for a greatly improved cd command. It supports things like "cd ..." and "cd ...." and so on in order to quickly navigate upwards.

link|improve this answer
feedback

I use alias …='cd ..' in my .bashrc file. Unicode rules ;)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.