1

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!

Community
  • 1
  • 1
Charles
  • 99
  • 2
  • 11
  • `.` `..` isn't specific to the `cd` command. It is expanded by your shell eg bash. Your shell exands `.` to the current working directory and `..` to the parent of the working directory. – hetepeperfan Feb 23 '15 at 10:39
  • Using this logic, could I create some kind of interpreter to change `(.. + . * n)` into a valid directory? – Charles Feb 23 '15 at 10:43

2 Answers2

3

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.

Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
1

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 ...

Sebastian Stigler
  • 6,819
  • 2
  • 29
  • 31