One Thing Well

A weblog about simple, useful software.

You can follow along on Twitter or via the feed. Don't hesitate to get in touch. Sponsor the site.

Fix Command

fc is a shell builtin command that lets you do some cool stuff with your shell history.

Run it without any arguments, and you can edit the previous shell command in your text editor of choice1. To run your freshly-edited command, just save and quit.

fc -l returns a numbered list of recent commands (just like history).

fc followed by one of those numbers will open that command in your editor.

If you follow fc with a string, it’ll open up the last command starting with that string—eg. fc mpl will open the last mplayer command.

That’s just the basics—you can do all sorts of crazy command editing gymnastics with fc, but the details vary from shell to shell. For details, see: bash, ksh and zsh.

Thanks, @gummo!

See also:


  1. As in $EDITOR. If you’d rather use something else, you can set $FCEDIT in your shell profile. If neither one is set, fc defaults to ed, which doesn’t stand for ‘extremely difficult’, but probably should.