How to fix macOS command line errors

If you are one of those who have spent time with your Terminal command line, chances are that on some occasion you have made a typographical error, or two, or hundreds if your writing precision is similar to ours at the time of writing items like this.

It is one of the nightmares of working with Unix. After years of point and click, having to type sometimes long and complex commands by hand leads to surprising typos and inaccuracies.

And sadly, Terminal is not as forgiving of typos as any current word processor such as Microsoft Word or Google Docs can be, which immediately marks the word in red for spell checking.

Let’s see an example in which we try to change the directory to the Applications folder. The command would look like this in Terminal (where% is the command prompt):

% cd Appplications

However, in haste when typing the command, it turns out that you type “Appplications” instead of “Applications”. Terminal will very kindly suggest:

RELATED:   How To Download macOS Big Sur ISO + DMG + VMDK files

cd: no such file or directory: Appplications

One way to correct this error is to use the arrow keys on your keyboard to navigate to the correct place in the command and press ‘Delete’ in the correct place. (This is most practical if the command is short and it doesn’t take long to do it again.)

This is a potentially easier method for more complicated commands: use the caret (^) character. Immediately after receiving the error in Terminal, start the following command with the caret.

Next, type the part of the above command that you want to correct, type another caret, and retype the corrected version of the command. In this example, it was three o’clock p the ones that were wrong, as there should only have been two.

To fix this, you will need to enter this command:

^ ppp ^ pp

When you press ‘Return’, Terminal will rerun the previous command, making the correction you just hinted at. And to let you know what happened, Terminal will also echo the corrected command that was run:

RELATED:   How To Install Macos Catalina On Unsupported Mac

% cd Appplications

cd: no such file or directory: Appplications

% ^ ppp ^ pp

cd Applications

[email protected] Applications%

You may not use this every day, but it’s a time-saving trick if you’re someone who spends time programming and developing with the Terminal command line.

You may also be interested in knowing the most important keyboard shortcuts that you should know how to handle on a Mac.

Original article published in Macworld US.

Leave a Reply

Your email address will not be published.

You May Also Like