Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am logged into ssh to a university account from my home computer. Then I find a file that I want to copy onto my local system. So I open a new shell terminal and am about to use scp to copy that file onto my system. But the path to the file on the system I am ssh'ed into is long so I select it with the mouse and then paste it with the mouse into the other locally connected terminal.

What I would like to do is something along the lines of: feed the output of pwd into a variable that is temporary and visible to all terminals even though I made it under the ssh'ed terminal, or some other way that I can't think of.

share|improve this question
2  
This is not quite an answer to your question, but a "solution" to your problem; just copy the file to an easy to type location (cp <file> /tmp, and then in the other terminal scp host:/tmp/<file> .). No need to remember difficult paths, or commands. –  kasterma Dec 6 '10 at 4:14
    
Apparently, using symlink instead of copying can save you some space if the file is not small enough. –  alex Dec 6 '10 at 6:18

4 Answers 4

up vote 3 down vote accepted

The way to do that is to use an ordinary file or a named pipe.

Why not do the scp in the original terminal in the first place (even in the background)?

If the host system uses proc, in the second terminal do cd -P /proc/PID/cwd then do your scp from . (where PID is that of the shell which is in the cwd/pwd that you are interested in).

share|improve this answer
    
i have only pwdx on my distribution –  Vass Dec 6 '10 at 11:15
    
for cd -P /proc/PID/cwd I get "-bash: cd: /proc/PID/pwd: No such file or directory" in the host system's terminal, should i be replacing PID with the PID of the running terminal on the system? –  Vass Dec 6 '10 at 11:32
    
@Vass: Yes, the PID of the shell that you're trying to get information from, as stated in my answer. –  Dennis Williamson Dec 6 '10 at 14:59

If your terminal supports the zmodem protocol (KDE's Konsole does), and the remote system has the lrzsz package installed, you can trigger a direct transfer via the terminal using:

sz foo.txt

Konsole prompts you were to save the file and that's that. GNU screen apparently has zmodem support too.

share|improve this answer
    
Here's a walkthrough: adammonsen.com/post/256. You need screen as well as rz/sz on your local machine. –  Janus Dec 6 '10 at 3:54

If you have ssh server running on your home machine, you may do the reverse scp:

[student@university ~/rather/long/path/to/interesting/file]$ scp ./secrect.txt user@myhomesystem.net:~

share|improve this answer

If you have X forwarding active (ssh -X, ForwardX11 in ~/.ssh/config, or any other method), you can manipulate the X selection from the shell:

printf %s "$PWD" | xsel -i

Depending on your terminal emulator, you may want to set the CLIPBOARD (xsel -bi) instead of the PRIMARY selection (xsel -p). You can also use the SECONDARY selection (xsel -si).

You can use the middle mouse button to paste the PRIMARY selection, or (in some terminals) the CLIPBOARD with Ctrl+V, or you can use xsel (or xsel -s or xsel -b) in the shell on the other side.

There are other possible workflows, involving for example a reverse ssh connection, ~ escapes, or zssh. See SSH easily copy file to local system, Download a file over an active SSH session. You could also mount the remote filesystem over sshfs.

share|improve this answer
    
Hah, my first thought was to xprop stuff it in some property on the root window, but xsel/xclip selections make more sense. –  ephemient Dec 6 '10 at 2:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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