Copy Present Working Directory (PWD) From Command Line

By | May 3, 2011

So, its been too long since I updated this place. So, today I’m gonna share you some simple tip that might save some time when you are working with multiple terminals. When you are working on multiple terminals you might experience a need to copy the pwd of one terminal and use it on the other.

Generally this is done by using linux command pwd and copying the current directory of this terminal (lets call it A). Later you go to the other terminal (lets call it B) and use cd command with the copied working directory (from terminal A) to enter that directory.

Now, this process didn’t look good for me. I just wanted to save some time by copying the present working directory of terminal A with just a single command. So this is what I did. Note: This should work with Debian and Ubuntu.

apt-get install xclip
sudo touch /usr/local/bin/copy
sudo chmod 777 /usr/local/bin/copy

Now, edit the file and paste this line.

pwd | xclip

Save the file.

Now, open a terminal and go to any directory you want and just type the command “copy” to copy the present working directory.

copy

Open a new terminal and type “cd” and middle click your mouse button to get the copied current working directory of the other terminal.

cd (now middle click the mouse and press enter.)

Now, command should certainly save you some time, I guarantee that for sure.

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!

Leave a Reply

Your email address will not be published. Required fields are marked *