I know a few advanced ways, to change directories. pushd
and popd
(directory stack) or cd -
(change to last directory).
But I am looking for quick way to achieve the following:
Say, I am in a rather deep dir:
/this/is/a/very/deep/directory/structure/with\ lot\ of\ nasty/names
and I want to switch to
/this/is/another/very/deep/directory/structure/with\ lot\ of\ nasty/names
Is there a cool/quick/geeky way to do it (without the mouse)?
To change directories, use the command cd followed by the name of the directory (e.g. cd downloads ). Then, you can print your current working directory again to check the new path.
The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.
By default, bash shows just your current directory, not the entire path. To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory.
Trying to use cd inside the shell script does not work because the shell script runs in the subshell and once the script is over it returns to the parent shell, which is why the current directory does not change.
Do you mean that the path names are the same, and only one directory name changes ("a" becomes "another")? In that case:
cd ${PWD/a/another}
will switch to the other directory. $PWD
holds your current directory, and ${var/foo/bar}
gives you $var
with the string 'foo' replaced by 'bar'.
What about setting up your CDPATH
variable?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With