命令行神器 The Fuck,敲错命令的后悔药

大家好,我是 Immerse,一名独立开发者、内容创作者、AGI 实践者。

  • 关注公众号:#沉浸式趣谈,获取最新文章(更多内容只在公众号更新)
  • 个人网站:https://yaolifeng.com 也同步更新。
  • 转载请在文章开头注明出处和版权信息。

我会在这里分享关于编程、独立开发、AI干货、开源、个人思考等内容。

如果本文对您有所帮助,欢迎动动小手指一键三连(点赞、评论、转发),给我一些支持和鼓励,谢谢!

分享一个命令行实用程序 --- TheFuck

它自动地纠正先前控制台命令中的错误。当命令失败时,用户可以输入 fuck 然后 TheFuck 会建议修正基于错误输出,允许用户快速修复拼写错误、权限问题或语法错误,而无需重新输入整个命令。

安装

基本要求

  1. Python 3.5 或更高版本
  2. pip(Python 包管理器)
  3. python-dev(开发头文件)

可通过下面的命令来验证当前系统是否满足安装要求:

sh 复制代码
python --version
pip --version

其他系统/Windows

sh 复制代码
pip install thefuck

macOS or Linux

sh 复制代码
brew install thefuck

Ubuntu/Debian

sh 复制代码
sudo apt update
sudo apt install python3-dev python3-pip python3-setuptools
pip3 install thefuck --user

FreeBSD

sh 复制代码
pkg install thefuck

原理

当命令失败时,它会分析错误输出并应用规则来建议修正。然后用户可以接受或拒绝修正,TheFuck 执行了更正后的命令。

sh 复制代码
➜ 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 [enter/↑/↓/ctrl+c]

使用实例

sh 复制代码
➜ 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 [enter/↑/↓/ctrl+c]
[sudo] password for nvbn:
Reading package lists... Done
...
sh 复制代码
➜ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master


➜ fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
sh 复制代码
➜ puthon
No command 'puthon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)
zsh: command not found: puthon

➜ fuck
python [enter/↑/↓/ctrl+c]
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
...
sh 复制代码
➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.

Did you mean this?
    branch

➜ fuck
git branch [enter/↑/↓/ctrl+c]
* master
sh 复制代码
➜ lein rpl
'rpl' is not a task. See 'lein help'.

Did you mean this?
         repl

➜ fuck
lein repl [enter/↑/↓/ctrl+c]
nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848
REPL-y 0.3.1
...

这个工具很方便使用,自己之前敲错命令,要不 --help,要么 GPT,这个过程也需要时间,而现在,直接 fuck,一边能解决问题,一边有点莫名的爽感,哈哈哈~

其他好文推荐

2025 最新!独立开发者穷鬼套餐

Windows 安装 Claude Code 的新姿势,保姆级教程

最近 Vibe Coding 的实践经验分享

分享一款 AI 自动生成流程图的工具

一个 Cursor mdc 自动生成器,基于 Gemini 2.5,很实用!

这个 361k Star 的项目,一定要收藏!

搞定 XLSX 预览?别瞎找了,这几个库(尤其最后一个)真香!

1分钟把简历变成个人网站!这个免费工具太香了

关于 MCP,这几个网站你一定要知道!

做 Docx 预览,一定要做这个神库!!

【完整汇总】近 5 年 JavaScript 新特性完整总览

关于 Node,一定要学这个 10+万 Star 项目!

相关推荐
补码缩写15 分钟前
视频跳转触发了seeked,画面就到位了吗
前端
库拉镜像AI牛牛19 分钟前
漫剧工作室量产方案:依托知漫剧 AI 短剧降本增效
大数据·服务器·前端·人工智能·语音识别
我的div丢了肿么办21 分钟前
go语言中管道 channel的使用
后端·go
Harvil_27 分钟前
模型点三道菜,回喂被拒 400
后端
不可能片场28 分钟前
内容运营自动化 用相似度拦住撞车选题
前端·electron
静默回滚29 分钟前
视频进度条跳回去,先别改事件监听
前端
Lank_M34 分钟前
MP4和WebM导出后为何起播与拖动不同
前端
用户55084929025636 分钟前
前端本地存储怎么选:Cookie、localStorage、sessionStorage、IndexedDB 的取舍
前端
用户55084929025636 分钟前
Git 日常命令与分支协作流程:从提交到合并的实战梳理
前端
修炼的dance36 分钟前
同一段视频没降画质为什么就快了
前端