I have been trying to install a Nagios package and stumbled upon these weird bash expansions on a guide here. Can someone help me understand what do the expansions mean? A wiki link would also be helpful for future reference.

root@z:~> wget http://mathias-kettner.de/download/check_mk-1.1.7i5.tar.gz
root@z:~> tar zxvf !#:t
root@z:~> chown -R root:root !$:r:r && chmod -R o-w !$:r:r && cd !$:r:r
root@z:~/check_mk-1.1.7i5> ./setup.sh
  • If anyone reading this has the rep for a 1-character edit, there's now an https version of the URL linked to in this post.
    – AJM
    Dec 7, 2022 at 17:42

1 Answer 1


These are bash history expansion keywords. They select a line from the shell history and reinsert (portions of) it, possible after modification. The site you linked to does a reasonable job explaining them, but it doesn't describe all of them.

tar zxvf !#:t

doesn't actually make sense: !# selects the line typed so far, but that's tar zxvf and we don't want to re-use any of that. It should be

tar zxvf !$:t

which selects the last portion of the previous line (!$), which is the URL given to wget, and takes the filename portion (:t, for tail — strictly speaking it's whatever's left after the last directory separator, /, which happens to work nicely with URLs).


chown -R root:root !$:r:r

selects last portion of the previous line, drops the file extension (:r — strictly speaking, it removes whatever's after the last ., including the .) twice, which gives the directory name (assuming the tarball contains a directory with the same name as the tarball's base name). The chmod and cd commands proceed in the same way.


You must log in to answer this question.

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