Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

This seems like an obvious question to me but I can't find the answer... Presume I want to find a certain txt-file in my project and in Terminal I type:

find -name test.txt

As result I might get something like:


How do I jump to directory4 without having to type the complete path?

share|improve this question

I'd use bash's history support to do this. After any command, you can reference it again with !!:

[jk@pecola tmp]$ find . -name test.text

To perform a ls -l on the output of the last command:

[jk@pecola tmp]$ ls -l $(!!)
ls -l $(find . -name test.text)
-rw-rw-r-- 1 jk jk 0 Jan 23 20:49 ./directory1/directory2/directory3/directory4/test.text

In this example, we use the $(...) syntax to use the output of the command as an argument to another command.

Because !! references the last command run, we now need to be more specific if we want to re-run the find command, since we've run ls since. We can use the !<match> syntax to re-run the last command that started with <match>

[jk@pecola tmp]$ dirname $(!find)
dirname $(find . -name test.text)

[jk@pecola tmp]$ cd $(dirname $(!find))
cd $(dirname $(find . -name test.text))

[jk@pecola directory4]$ ls

I also find this handy for re-doing commands which you need sudo for:

[jk@pecola tmp]$ adduser newuser
adduser: Only root may add a user or group to the system.

[jk@pecola tmp]$ sudo !!
sudo adduser newuser
share|improve this answer
Thanks, I didn't know about !! and $(...). They’re surely handy! Although I'm a little surprised that's such an "easy task" is quite a hassle, I think this solution will do! – Ludder Jan 23 '13 at 19:36

If the terminal session is within a GUI you can select text with your mouse (left button) and paste the whole text at the position of the text cursor by clicking the middle mouse button.

share|improve this answer
Thanks, I didn't know about the middle click (I use shift+insert instead). I prefer a keyboard only solution though. – Ludder Jan 23 '13 at 19:31

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.