Switch between directories in an automated way without using cd

Bash

There are several ways to change from one directory to anotherYou already know that the most used is the cd command from the terminal, but it is not the only one. We can also create environment variables like $ HOME to point directly to routes that we use often and thus avoid having to type them completely to go to them. In this tutorial we will see how we can do that in a simple way by editing one of the configuration files of Bash, our favorite command interpreter for Linux.

For example, imagine that you want to always have any directory accessible. Since you work a lot with directories and you would like to change from one to another saving keystrokes, that is, quickly without having to always type cd in front of the path of the directory you want to go to in the console. Well, let's see step by step how to do it by editing the .bashrc file that is in our personal directory (since it will only affect our user).

For editing we must use your favorite text editor, like for example nano:

nano ~/.bashrc

And there we will add a line at the end which is:

shopt -s autocd

Save the modification and exit the text editor. Now we must to update changes with:

source ~/.bashrc

Now everything is ready, every time you want to go to a directory, you just have to type its name, without accompanying it with a cd in front of it. For example, if we want to access Desktop and I am in my user's home directory, I could do this:

cd Escritorio/

But it is no longer necessary, with a simple:

Escritorio/

It would be enough to go. And if later we want go to another directory inside it called Test:

Prueba/

And it would already be in ~ / Desktop / Test saving us the two cd's that we should have inserted if we had not done the setting...


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.