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.
!! 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
[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