how to save path names in variables in linux terminl
Shell: bash
I'm connecting to a remote linux machine via the shell. My issue is that I'm constantly going back and forth between a few directories and its getting annoying to type out their names. I know about tab complete, and I'm trying to explore !!, but right now theyre not as efficient as I want them to be. I am also aware of the arrow functionality that goes through the command history. I want to just save the paths in variables like this myPath="/blah/dee/blah/files" and then type the command cd myPath. Is this not possible, or am i missing something? Or, how can I do something similar to this using !! or another command? |
I am also aware of using the arrows to go through my command history
|
There are various possibilities, depending on the exact sequence of things in your situation. These include at least:
For example, if you are jumping back and forth between two directories A and B which both have the same parent directory, and you start in the parent directory: Code:
cd A If you then issue the command: Code:
cd - The commands pushd and popd as well as some related commands, will allow you to manipulate a directory stack of sorts, if that could suit your needs. The CDPATH environment variable can be given a list of directories, much like the PATH variable. But each of the directories in the CDPATH variable can serve as the base for a set of directories which as a sort of shortcut form of the cd command; each of them can be cd'd into just giving the contained directory name to cd. As an example, suppose a directory named files1 contains directories named A B C and D, a directory named files2 contains directories named V W X Y and Z. Code:
export CDPATH=/blah/dee/blah/files1:/blah/dee/blah/files2 Code:
cd A |
Quote:
Code:
cd "$myPath" Tip: Quotes are only necessary if there are spaces in the directory names, eg: myPath="/path/to/some directory" Code:
myPath="/tmp" but it is not required if there aren't any spaces the directory name. Both could be assumed 'correct' I guess. |
All times are GMT -5. The time now is 11:43 AM. |