Skip to content

Today I Learned (TIL)#

This is a second blog, intended for shorter posts about discoveries I make or insights I gain.

A time-saving way to re-run your last terminal command but with substituted parts

Abstract

Introducing the shell command fc and its option -s.

I already wrote two articles about the Z shell’s built-in r (with no or one argument and with two arguments) which really only is an alias for a particular use case of the command fc. So today, let’s stop scratching the surface that is the command r and dig deeper by examining the command fc. There’s a lot more to discover about that fc command.

A time-saving way to re-run your last terminal command

Abstract

Introducing zsh’s command r and how to re-create it in bash.

The Z shell has a built-in named r that optionally takes an argument, and re-runs/repeats

  • the last command in your history that begins with the given argument (if an argument was given).
  • the last command in your history, period (if no argument was given).

Example

Imagine you executed these commands:

pip install --upgrade pip
echo "I just upgraded pip."

Executing r pip would execute the last command in your history that begins with pip. In our case, it would run pip install --upgrade pip again.

Running simply r (without any argument) would run the last command again. In our case, it would run echo "I just upgraded pip." again.