Saturday, April 27, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 872  / 3 Years ago, sat, september 18, 2021, 3:26:25

Something similar to this Q&A, I know that cd will change current working directory in terminal to a new directory like this:



cd /path/to/new_directory


But I wonder how can I change current working directory only by typing for example:



/path/to/new_directory


followed by Enter, of course. Nothing more.


More From » command-line

 Answers
6

I just find out that by activating autocd shell option, using the following command:



shopt -s autocd


then




a command name that is the name of a directory is executed as if it
were the argument to the cd command




(from man bash, somewhere at the line 5131).



So it will actually let me use any directory as a command and will cd to it:



cd



To make the change permanently, add the following line to the end of your ~/.bashrc file:



shopt -s autocd

[#24220] Sunday, September 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
njuash

Total Points: 402
Total Questions: 125
Total Answers: 98

Location: Jersey
Member since Sun, Dec 4, 2022
1 Year ago
;