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.
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 thefuckConfiguration
# Edit bash configuration
vim ~/.bashrc
# Add an alias for thefuck (e.g., "fuck")
eval "$(thefuck --alias fuck)"
# Apply changes
source ~/.bashrcExamples
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 vimFirst git push without upstream
➜ git push
fatal: The current branch master has no upstream branch.
➜ fuck
git push --set-upstream origin masterMisspelled python command
➜ puthon
No command 'puthon' found, did you mean:
Command 'python' from package 'python-minimal' (main)
Command 'python' from package 'python3' (main)
➜ fuck
pythonHow 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-worksThis guide provides the essential steps to get The Fuck up and running, enabling smoother command‑line workflows.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
