I am working on macos and on the terminal app I am connecting to a server which run on linux, through ssh -X (and I actually I should not be allowed to install any software on it).

In order to save time, I would like to set an alias, thus a keyboard shortcut, to copy the current directory path directly to the clipboard, instead of writing pwd and the manually copying the output.

On local, on the .bashrc on my mac locally I have found and using this:

  alias pcd='pwd | pbcopy'

but it does not work on the ssh server if I copy this on the .bashrc file of the remote machine.

I was thinking that I could use an alias to write pwd to remote terminal's output but then I do not know how to copy it to the clipboard.

Please not that I want to be able to paste the path of the directory to the remote machine terminal, even if once is copied on the clipboard it should work in both directions I guess, (unless the remote machine has its own clipboard).

Actually I also don't know it there would be any difference in the procedure if I would be working on linux pc instead of apple?

  • Can you please state clearly in the question (1) What are the clipboard commands available on your machine and in the server, (2) which of the two machines should have the path be copied to its clipboard and (3) what is pbcopy?
    – Quasímodo
    Oct 10, 2020 at 14:33
  • Trough the ssh connection I usually write pwd, select the path and with cmd+d I copy it to my mac clipboard and I can also paste it again to the remote machine terminal. Regarding pbcopy I am not sure how does it work with the local command actually, I have just found this solution on internet and I would like an equivalent way to do it working on the remote machine terminal. Oct 10, 2020 at 15:05

1 Answer 1


pbcopy and pbpaste are commands that are specific to macOS and don't work on Linux. Typically, the commands that can be used instead are xclip and xsel (you need one or the other, not both). These are not built-in commands, but extra packages, and usually have to be explicitly installed, especially on headless machines.

Since you're using ssh -X, you can copy with xclip or xsel to the X11 clipboard if one of those commands is installed on the remote system. If you also want to paste it to the remote system, then that should be sufficient for your needs: all you need to do is invoke the relevant paste command in your X11 server.

If you want to interact with the Mac system clipboard, then you will need to have your X11 server do that for you. Whether your X11 server does that is unknown, because you haven't told us which one you're using. The macOS graphics system is not network transparent, unlike X11, so there's no other way to get data from the remote system to your clipboard on the Mac. You also need to be sure that your X11 configuration is properly set up such that you have a non-empty DISPLAY variable when logged into the remote system.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .