Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    Is there a way to get the second-last item? i.e. get file3 from mv file1 file2 file3 target/? Commented Nov 26, 2016 at 15:35
  • 4
    I liked this answer a lot and just for the completeness sake, I suggest to also add a line telling about '!-2' syntax that allows you to access previous to previous command.
    – bbv
    Commented May 17, 2017 at 8:05
  • 1
    @bbv Also for even more completeness the command '!2' which allows you to access the second entry in the history (if it's still available depending on your history settings). Useful if you display the history number in each prompt.
    – 816-8055
    Commented Nov 22, 2019 at 13:32
  • There's also !:-2 which gives you everything up until the 2nd argument. In this case echo a b.
    – Lubo Kanev
    Commented Jun 14, 2022 at 13:57