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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ pidof qqq
$ cd /proc/
           ^ cursor here

And now I want to auto-insert the previous line here. Of course I can manually type 12345 or `pidof qqq`, but how to do it conveniently?

The question is not solely about pidof and /proc, but about any such situation of reusing previous command output.

share|improve this question
What are you aiming at? cd /proc/12345? – Bernhard Sep 12 '13 at 11:10
Yes, for example. – Vi. Sep 12 '13 at 11:14
cd /proc/$(pidof qqq) – Rahul Patil Sep 12 '13 at 17:15
@RahulPatil What shall I press to avoid manually typing $(pidof qqq) or copying? The whole point is to save typing. – Vi. Sep 12 '13 at 22:01

You can use the following:

cd /proc/$(!!)
share|improve this answer
That is just rerunning the previous command which could output something different the second time it is ran. – llua Sep 12 '13 at 11:23
Or `!!` - even easier to type (if there is no backticks in previous command). – Vi. Sep 12 '13 at 11:23
@llua Good point, the command might also have some other undesirable side-effects (e.g. script which starts a daemon and outputs the pid of the newly created process). – Thomas Nyman Sep 12 '13 at 11:38
Maybe the correct implementation should be on side of pseudo-terminal master? I.e. it should be gnome-terminal's (or whatever) shortcut like "Insert penultimate line here". Related: stackoverflow.com/a/10059590/266720 – Vi. Sep 12 '13 at 12:20

Your Answer


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.