The Linux command that you should never say out loud

angry dead cat
Credit: flickr / dead cat

If, when working on your Linux servers, you occasionally mistype a command and then curse, you might feel right at home with a very oddly named Linux command. It might even reduce the frustration you feel by helping you to correct your typing mistakes. The tool is called, well, thef?ck -- but with the ? replaced by the obvious letter. And, in spite of its rather off-color name, a lot of people are very excited to have a little help getting past their command line mistakes.

Installing the command

The commands shown below should get the command installed on your system. The pip command helps install Python packages.

$ sudo yum install pip
$ which pip
$ PATH=$PATH:/usr/local/bin
$ wget -O - https://raw.githubusercontent.com/nvbn/thefuck/master/install.sh | sh - && $0
$ sudo -H pip install thefuck

And, to ensure that I behave myself on the command line (who knows who might end up reading my history file), I created an alias for the f?ck command.

$ alias fix=/usr/local/bin/f?ck

Just don’t forget to replace the ? as described above.

OK, so from now on I can call the command “fix”. Let’s take a look at what fix can do for you.

Using the fix alias

First, let’s make a mistake and see what happens. I’ll deliberately misspell a command argument.

$ cd /usr/lcal/bin
-bash: cd: /usr/lcal/bin: No such file or directory

Then, I type “fix” to get a little help.

$ fix
mkdir -p /usr/lcal/bin && cd /usr/lcal/bin [enter/↑/↓/ctrl+c]
Aborted

OK, so maybe that wasn’t the help I was hoping for, but the suggested command change would have worked; it just wouldn’t have done the smartest thing (i.e., take me to the intended but misspelled subdirectory). So, I hit control-C instead and aborted the replacement command. Of course, in this case, if I’d blindly pressed the enter key for this command, I would have received a “cannot create directory” error since I don't have write permission to /usr/local/bin.

Sometimes the fixes suggested by fix work out well and sometimes they don’t. When I mistype a command name, I get a better suggestion.

$ sdo vim /etc/passwd
-bash: sdo: command not found
$ fix
sudo vim /etc/passwd [enter/↑/↓/ctrl+c]

In this case, the fix command is probably only slightly faster than editing the command by typing ^s^su^. Sometimes fix helps a lot, sometimes only a little.

Here are a couple examples using the fix command for date misspellings: .

$ datee
-bash: datee: command not found
$ fix
date [enter/↑/↓/ctrl+c]
Tue May 10 19:04:28 EDT 2016
$ daet
-bash: daet: command not found
$ fix
date [enter/↑/↓/ctrl+c]
Tue May 10 19:04:41 EDT 2016

The fix command won’t always suggest the command that you had in mind –- as shown in the following example.

$ aptget install netcat
-bash: aptget: command not found
$ fix
date install netcat [enter/↑/↓/ctrl+c]
date: extra operand ‘netcat’
Try 'date --help' for more information.
$ aptg-et install netcat
-bash: aptg-et: command not found
$ fix
gpg-agent install netcat [enter/↑/↓/ctrl+c]

You can also get some interesting effects when using fix. In the command sequence below, we can see that “fix” makes use of commands that I’ve entered in the past. Though my echo command was perfectly valid, the fix that follows yanks a command from my history file.

$ echo Hello, World!
Hello, World!
$ fix
echo Hello, World! | rev [enter/↑/↓/ctrl+c]
!dlroW ,olleH

One caution

One caution is in order. If you use the “fix” command (or the command by its original name), always verify that the suggested command is the one you had intended to type. Some people have reported f?ck confusing itself for fsck. The fsck command is clearly one you don’t want to run by mistake. I haven’t run into that though I see it does, as I'd expect, try to fix misspellings of fsck.

$ fcsk
-bash: fcsk: command not found
$ fix
fsck [enter/↑/↓/ctrl+c]

Wrap-Up

The “fix” command is clearly one of more unusual commands that I’ve come across, though it’s one that at least was put together with a good intention or two – maybe both to fix your mistakes and give you a chance to let off just a bit of steam.

 

 

This article is published as part of the IDG Contributor Network. Want to Join?

To express your thoughts on Computerworld content, visit Computerworld's Facebook page, LinkedIn page and Twitter stream.
Related:
Windows 10 annoyances and solutions
Shop Tech Products at Amazon
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.