Ubuntu – use cd../.. as an alias name

aliasbash

I am using Windows and Ubuntu in parallel and do console stuff on both of them.

On Windows I can do a

C:\Users\Thomas>cd..\..
C:\>

However, on Linux this does not work, neither with backslashes nor with forward slashes.

21:17:10 $ cd../..
bash: cd../..: No such file or directory

Since I often make that mistake, I have tried to define an alias in .bash_aliases for that situation:

alias cd../..='cd ../..'
alias cd..\..='cd ../..'

When I start a new bash, I get

21:16:26 $ bash
bash: alias: `cd../..': invalid alias name

How would I set up aliases for cd..\.. and cd../.. correctly?

The cd..\.. seems to have problems with the escape character:

21:39:43 $ cd..\..
bash: cd....: command not found

It does not work, even if I define another alias for cd.....

Best Answer

/ and \ are among the characters which cannot appear in a Bash alias name. From man bash:

The characters /, $, `, and = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

As a workaround, you can switch to Zsh, which allows both:

% grep 'alias.*cd' .zshrc 
alias cd../..='cd ../..'
alias cd..\\..='cd ../..'
% pwd
/Users/firas
% cd../..
% pwd
/ 
% cd
% pwd
/Users/firas
% cd..\..
% pwd
/