Celeb Glow
news | March 17, 2026

Copy-and-paste current working directory on command line without using the mouse

I am using the terminal quite a lot, but I am frustrated that I repeatedly resort to the mouse in the following situation.

I have two terminal tabs open with the current working directories X and Y, respectively. In the tab where the directory is X, I want to do this (as an example):

cp somefile Y

The path Y could be very long, so my current, and cumbersome, method is to do

  1. Ctrl+PgUp to change tab,
  2. write pwd to show Y,
  3. use the mouse to select the output from pwd,
  4. Ctrl+PgDown to go back to the first tab,
  5. use the mouse again to paste Y after cp somefile, using middle-click.

Surely this procedure must be avoidable, for example by having a shortcut that copies the current working directory without using the mouse. Any suggestions?

4

1 Answer

Here is a quick tutorial about how you can copy text from terminal using only keyboard:

  1. Open screen: screen (you can install it using sudo apt-get install screen command if you don't have already installed)
  2. Run your program, producing output you want copied (in your case pwd)
  3. Enter copy mode: Ctrl+A followed by [
  4. Move your cursor to the start point using arrow keys
  5. Hit Enter
  6. Move your cursor to the end point using arrow keys
  7. Hit Enter
  8. Paste: Ctrl+A followed by ]

Source:


Or, because you use more tabs, is better to use xsel. To install it, run the following command:

sudo apt-get install xsel

Then in second tab run:

pwd | xsel -b

and in first tab (or wherever you want) paste from clipboard using Ctrl+Shift+V.

Source:

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy