If you’re working with files in the Terminal and switching back and forth between two directories, we’re about to save you some time. There is a shortcut command that allows you to toggle between two directories on the command line.
First, as usual, change to your first directory by typing the following command at the prompt and pressing Enter.
cd First/Directory/
RELATED: Use Tab Completion to Type Commands Faster on Any Operating System
Where First/Directory/
is name of the directory you want to change to.
You can also use tab completion to enter the directory name by typing a few characters in the name and then pressing Tab to finish entering the name.
Now, we want to switch to a second directory, so we use the cd command and tab completion again.
Now, instead of typing the first directory name to go back to that directory, you can type the following command at the prompt and press Enter.
cd -
That’s simply the cd
command followed by a space and then a dash. The name of the directory you’re toggling to displays and then you’re taken to that directory.
To toggle back to the second directory again, use the cd -
command again.
You can also press the up arrow key once to access the last command used from the command line history, which in this case was cd -
. So, at this point, to toggle back and forth between these two directories, all you do it press the up arrow key and Enter. That’s quicker than typing out the path each time, even when you use tab completion.
- › 5 Ways to See If Your Phone Is Being Tapped
- › 10 Kodi Features You Should Be Using
- › Physical vs. Digital Games: Should You Buy Physical Games?
- › How to Add a Shortcut to Pretty Much Anything on Android
- › What You Should (and Shouldn’t) Unplug or Turn Off When You Go On Vacation
- › 5 Reasons to Upgrade to the 11th Gen Kindle Paperwhite