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 YThe path Y could be very long, so my current, and cumbersome, method is to do
- Ctrl+PgUp to change tab,
- write
pwdto show Y, - use the mouse to select the output from
pwd, - Ctrl+PgDown to go back to the first tab,
- 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?
41 Answer
Here is a quick tutorial about how you can copy text from terminal using only keyboard:
- Open screen:
screen(you can install it usingsudo apt-get install screencommand if you don't have already installed)- Run your program, producing output you want copied (in your case
pwd)- Enter copy mode: Ctrl+A followed by [
- Move your cursor to the start point using arrow keys
- Hit Enter
- Move your cursor to the end point using arrow keys
- Hit Enter
- 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 xselThen in second tab run:
pwd | xsel -band in first tab (or wherever you want) paste from clipboard using Ctrl+Shift+V.
Source:
4