Reputation: 99
So,
cd ..
moves back into the parent directory.
I'd like to add functionality so that I could type...
cd ...
... and move into the parent directory's parent directory.
and consequently move up an additional tier for each extra .
The idea came from an SO answer about a script called 'up' which should do essentially the same thing. But I'm curious if it'd be possible to just add to the cd
command.
After a quick search I've noticed that cd
is a bash builtin so I don't think it'll be possible to edit any original code. Would it be possible to create a new cd
(.sh) script that executes in place of the builtin cd
command when valid arguments are provided? What other ways might this be accomplished by?
Note: this is more for learning than practical application, I just think it'd be a cool thing to do. Thanks!
Upvotes: 1
Views: 119
Reputation: 7309
You can add the following lines to the file ~/.bashrc
alias cd..='cd ..'
alias cd...='cd ../..'
and so on.
After adding this lines close the terminal and open an new one. There you can us cd..
to go one directory up, cd...
to go two directories up ...
Upvotes: 1
Reputation: 22331
You can define an alias in your .bashrc
file:
alias ...='cd ../..'
and after that you can issue ...
to go up two directories. If you only want that alias for cd
it will work.
Upvotes: 3