Skip to content

[Linux] Using "The Fuck" Tool to Correct Mistyped Commands with fuck

Last Updated on 2024-09-19 by Clay

Linux has so many useful tools, and I truly want to document every single one of them. To celebrate Linux reaching a usage rate of 4.55% on StatCounter (2024-09-18), I've decided to document another tool recommended by a colleague—the fuck command.

fuck is another incredibly handy command-line tool. It automatically detects the 'correct' command format when we accidentally misspell or enter an incorrect command. It’s not just limited to command typos; it can also provide corrections for wrong parameters or order errors.

Rather than explaining more, let's dive in and see how to use it.


Installation

Whether you're on Windows, Mac, or Linux, as long as you have Python installed, you can install it using the following command:

pip install thefuck


After that, you can configure fuck for your shell. Since I'm using Linux, I'll document this part mainly for Linux. Next, you need to set up the alias. In the old instructions, I found the following configuration command:

echo 'eval $(thefuck --alias)' >> ~/.bashrc
source ~/.bashrc


However, for the new version, I found that simply typing fuck will automatically prompt you to add the alias fuck in your ~/.bashrc configuration file.


Usage

The usage of fuck is straightforward—when you accidentally type a command incorrectly and believe fuck can automatically correct it, just run fuck.

As shown in the example above, I mistakenly typed dc instead of cd. After angrily typing fuck, it automatically suggested the correct spelling.


Of course, the fuck command is just for fun. The most important thing is to train yourself not to make mistakes from the start.


References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version