Operations 4 min read

Fix Mistyped Shell Commands Instantly with The Fuck

Learn how to install, configure, and use The Fuck tool on macOS, Linux, and FreeBSD to automatically correct common command‑line typos and errors, with practical examples for sudo, git, and Python commands.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Fix Mistyped Shell Commands Instantly with The Fuck

Many developers frequently mistype commands in the terminal, such as typing python as puthon or using incorrect options like ls a‑lh. The thefuck utility can automatically detect these mistakes and suggest or execute the corrected command.

Installation

macOS/Linux (Homebrew): brew install thefuck FreeBSD (pkg): pkg install thefuck CentOS/Ubuntu (pip):

pip install thefuck

Configuration

# Edit bash configuration
vim ~/.bashrc
# Add an alias for thefuck (e.g., "fuck")
eval "$(thefuck --alias fuck)"
# Apply changes
source ~/.bashrc

Examples

Ubuntu installing vim without sudo

apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

➜ fuck
sudo apt-get install vim

First git push without upstream

➜ git push
fatal: The current branch master has no upstream branch.

➜ fuck
git push --set-upstream origin master

Misspelled python command

➜ puthon
No command 'puthon' found, did you mean:
  Command 'python' from package 'python-minimal' (main)
  Command 'python' from package 'python3' (main)

➜ fuck
python

How The Fuck Works

The tool uses rule‑based matching (regular expressions) to identify common mistakes and generate corrected commands.
cat_dir      – replace "cat" on a directory with "ls"
cd_correction – fix misspelled "cd" commands
cd_mkdir      – create a directory before changing into it
cd_parent     – replace "cd.." with "cd .."
dry          – fix duplicate commands like "git git push"
fix_alt_space – replace Alt+Space with a regular space
# More rules are listed at https://github.com/nvbn/thefuck#how-it-works

This guide provides the essential steps to get The Fuck up and running, enabling smoother command‑line workflows.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Shellcommand-linemacOSError Correctionthefuck
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.