If you need to frequently use the Linux cd command to jump to multiple subdirectories under a specific parent directory, you can consider setting the CDPATH environment variable to this parent directory.
For example, when several sub-directories under the/etc directory are frequently operated, we set CDPATH to/etc, you do not need to add the/etc prefix each time you go to the/etc subdirectory.
Code:
# Pwd
/Home/topsage
# Cd ssh
-Bash: cd: ssh: No such file or direcotry
Code: # export CDPATH =/etc
# Cd ssh
At this time, the cd ssh command will find the ssh subdirectory in the basic directory/etc:
Code:
# Pwd
/Etc/ssh
If you want to change the basic directory permanently, add the downloaded code to your ~ /. Bash_profile:
Code:
Vi ~. /Bash_profile
Export CDPATH =/etc
Similar to the PATH variable, you can add multiple paths in the CDPATH variable to separate multiple directories with semicolons (;). This makes it easier.
Code:
Export CDPATH = .:~ :/Etc:/var
This technique is helpful when you use the Linux cd command to jump to a specific parent directory:
Oracle DBAs often make some settings under the $ ORACLE_HOME directory. It is much easier to add the Oracle root directory in the CDPATH.
Unix-like system administrators often modify the configuration files in/etc. You can add/etc to CDPATH.
Program developers often work in projects such as/home/projects. CDPATH can also help a lot at this time.
End users (ordinary account users) often perform routine operations in their home directory. You can consider ~ Add the CDPATH variable.
You can use the CDPATH variable to speed up the operation of the Linux cd command.
- Linux basic commands-linux cd commands
- Linux cd commands and several tips on cd commands
- Linux cd commands