2

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?

  • Are you sure your workflow is well-thought? – gniourf_gniourf Oct 28 '13 at 13:47
  • I am pretty sure my workflow is not well-thought, but this is the best ad-hoc solution I can come up with given my current command-line skills. In general terms, I often face the scenario of working in two folders simultaneously (say doing rsync between them, cp, diff, running some command in one folder that pipes the output into the other, etc), and it is a recurrent issue I have that I need to type both paths (or the other) at the command line. It can be compared with having two panes open in Nautilus to allow drag-and-drop. Any suggestions on improving this workflow would be great! – DustByte Oct 28 '13 at 15:41
  • You might as well use a variable, e.g., remote="path to the/remote directory/" and then mv this_file_here "$remote"... but tab completion will then not work for subdirs of $remote (that can be cured by tweaking bash's completion, but it's not the simplest). Another possibility (and very likely the simplest) is to soft link to the remote directory in your working dir: ln -s /path/to/remote/dir ./remote and remove the link when you're done with rm remote. – gniourf_gniourf Oct 28 '13 at 17:50
  • Mmm... I can see potential in particularly the method of using soft links, combined with some simple alias/scripting. I could quickly set up a temporary link (path that is short, easy to remember and quick to type) for the remote directory. Thanks for the tip! In fact, using soft links for deeply located subdirectories is something I have been thinking about before, but the idea of using it also in a more temporary sense had not really crossed my mind. – DustByte Oct 28 '13 at 22:04
4

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: https://stackoverflow.com/a/312215/2353900


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: https://stackoverflow.com/a/318874/2353900

  • I do appreciate your answer, but I as I see it, it has two shortcoming: 1. I need to run screen (which I should arguably always do when using the command line, or?), 2. The number of keystrokes in addition to moving the cursor around seems a bit tedious, still. I also lose a few keystrokes just by swapping between windows, and under my keyboard layout, the [,]-keys require Alt Gr to be pressed. – DustByte Oct 28 '13 at 12:02
  • @DustByte See my new edits. – Radu Rădeanu Oct 28 '13 at 12:03
  • Ah, xsel seems promising. Will check it out. Thanks. – DustByte Oct 28 '13 at 12:06
  • 1
    xsel works well. I have now added my own alias, alias pwdc='pwd | tr "\n" " " | xsel -bi', so that writing pwdc (c for copy) does the trick. – DustByte Oct 28 '13 at 12:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.