Introduction
Here I show how to copy the path of current directory in memory in a Bash terminal, without a mouse, and use it in the current terminal or any new terminal opened afterwards. This is like when on Windows (or any other Desktop OS), you copy a path and then somewhere else you paste it. You can also use that path to navigate back there quickly, copy some content to it from somewhere else and so on.
Prerequistis
I am assuming you are familiar with Bash terminal and its commands.
Copy path (cppath)
Create ~/cppath.sh
file and add the below lines into your ~/.bashrc
source ~/cppath.sh
alias cppath='cppath=$PWD && echo cppath=$PWD > ~/cppath.sh'
Note that single quotation marks delay the expansion of cppath
alias, so don’t use "” there.
Now start a terminal and run
cppath
The current directory is stored in the cppath.sh
file and $cppath
variable that is available in the current terminal. Moreover, if you open a new terminal, .bashrc
is run and the content of cppath.sh
is pasted into $cppath
variable again and you have access to that path. So you can do
cd $cppath
#or
cp /home/blah/blah $cppath
To sum up, cppath
command copies the current directory path into $cppath
variable.
Latest Posts
- A C++ MPI code for 2D unstructured halo exchange
- Essential bash customizations: prompt, ls, aliases, and history date
- Script to copy a directory path in memory in Bash terminal
- What is the difference between .bashrc, .bash_profile, and .profile?
- A C++ MPI code for 2D arbitrary-thickness halo exchange with sparse blocks