In Bash, you can press Alt-. to insert the last argument of the previous command. If you press it multiple times, it cycles through the last arguments of all of the commands in your history. However, sometimes I press it too many times, and I want to reverse the direction of the cycling, hence go forwards. Is this possible?

(i.e. if you reverse-i-search with Ctrl-r, you can change directions with Ctrl-s. What is the analogue for Alt-.?)


If you supply a negative argument to Alt-., it reverses direction. The easiest way to do that (with standard keybindings) is Alt-- (equivalent to an argument of -1).

So, after one or more Alt-. keypresses, pressing Alt-- will cause the next Alt-. to go in the reverse direction. (Just ignore the argument dialog which appears when you press Alt--.)

  • 1
    I'm not sure what you mean exactly. Pressing Alt+- removes the command-line prompt and inserts (arg: -1) instead. The command itself is unchanged. – Sparhawk May 12 '13 at 6:23
  • 1
    Thenext alt-. (with the -1 arg) will go forwards. – rici May 12 '13 at 6:46
  • That's great! I've edited the answer to make it a bit clearer. What does alt+- do exactly? – Sparhawk May 12 '13 at 12:35
  • 1
    @Sparhawk: as I said, alt - produces an argument of -1 for the next readline command. Or, more precisely, it starts a negative argument, so alt -, alt` 2 would produce an argument of -2. In the case of alt ., only the sign of the argument matters, and only if it is negative, so alt - is sufficient. (The first alt . handles its argument differently. See the bash manual.) – rici May 12 '13 at 16:12
  • Thank you. I often find man bash slightly opaque for such situations, but I think it's clarified it a little here. – Sparhawk May 14 '13 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.