How can I copy the current path in the bash terminal, using just one command?
Asked
Active
Viewed 1.2k times
2 Answers
11
Needs xsel
installed:
pwd | xsel -i
(if you don't want the trailing newline, use printf %s "$(pwd)" | xsel -i
(mostly correct) pwd | head -c -1 | xsel -i
(perfectly correct))
Update August 2014: The xsel
program is broken: See my bugreport.
Probably you can get along with xclip
as well.

Jo So
- 25,005
- 6
- 42
- 59
-
+1 I'm not sure I understand the version that pipes through `head`, though. Why pass only the first byte to `xsel`? – chepner Mar 28 '13 at 20:04
-
this means "pass everything but the last byte" (which we know is the added newline) – Jo So Mar 28 '13 at 20:40
-
Oh, right. I was reading that as `head -c 1 -1`. – chepner Mar 29 '13 at 04:56
-
Unable to locate package xsel !..any other suggestion ! – CoDe Jun 26 '15 at 12:15
-
@Shubh: `xclip` can be used instead. Actually, `xsel` is quite buggy: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=758599 – Jo So Jun 26 '15 at 15:35
3
pwd | tr -d '\n' | pbcopy
Try this... Best I can come up with on my phone.

fedorqui
- 275,237
- 103
- 548
- 598

stevenelberger
- 1,368
- 1
- 10
- 19