Is there any shortcut for cd ..
?
9 Answers
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 ..
.
-
10
-
7I'm using also
alias ...="cd ../.."
and two more. Additionally, I can recommendalias ,=cd "$OLDPWD"
. Commented Mar 19, 2011 at 16:09 -
13
-
1@honk I didn't know it. However, it's too long (and I don't need the output). Commented Mar 19, 2011 at 16:25
-
1
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
-
2That is fantastic. Time to edit .bashrc on all my linux boxes. Unfortunately it doesn't seem to work with cygwin bash.– jugglerCommented Mar 19, 2011 at 19:42
-
3
-
6@gordoco: yeah, it's bash 4.x only. It's the reason why I've been using zsh for 14 years. Commented Mar 20, 2011 at 1:55
-
1
-
3@LaC: Technical superiority isn't always a determinant of dominance. Bash is far older and has far more written using it, and practically all shell programmers know it, more than anything else. Change can be hard. -- from someone who doesn't know what all the zsh noise is all about, and has only really ever used bash :)– tshepangCommented Apr 9, 2011 at 8:41
I find this useful:
up() { local p= i=${1:-1}; while (( i-- )); do p+=../; done; cd "$p$2" && pwd; }
For example, up 4
= cd ../../../..
As a bonus, `up 4`/path/to/file
works in a similar way to ../../../../path/to/file
.
-
1That'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! :) Commented Mar 20, 2011 at 8:57 -
Nice. I had something like this for VMS DCL when I worked on that, but didn't really think about it when I moved to Unix and its variants. Commented Oct 11, 2012 at 13:33
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
-
4
-
4
I use this one since I type too fast and often miss the space bar:
alias cd..="cd .."
-
Most inconvenient for a non-unix person occasionally on a *nix box +1 Commented Mar 19, 2011 at 17:52
-
11
-
3If you are typing so fast you are missing characters, it's hard to believe adding alias for
cd..
really helps.– OlliCommented Mar 20, 2011 at 12:25 -
3I can see how it could help if you come from dear old DOS, where
cd..
was valid :)– cambracaCommented Mar 20, 2011 at 19:02 -
1For 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. Commented Mar 20, 2011 at 20:35
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.
My bashrc file contains
alias ..="cd .. && ls -lG"
as well as
alias ,,="pushd .. && ls -lG"
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.
cd ..
too cumbersome to typecd ..
’ so often have the “I mustcd
into a directory before talking about the files there” anti-pattern, rather than specifying filesystem paths.