Terminal on Mac (macOS): what is it, commands, syntax — a clear guide for beginners

Today we are all 99% cases we work with Mac through a pleasant, intuitive and user-friendly graphical user interface.

But when solving a number of specific tasks, even Finder can’t cope with that, what the good old command line will do for instance, using it is much easier – and faster! – look for a 5 gigabyte file or application path that is lost somewhere in the bowels of the system, which, what did you think, already deleted long ago.

What «Terminal»?

Terminal – standard system utility for interacting with Mac using the command line. Linux has a similar management tool, t.to. both are unix-like.

Command line interface (command line interface or abbreviated CLI) – he is the language of communication with the Terminal – called bash. Everything, what we will talk about below – these are bash commands.

Common Commands for Mac

Basic syntax

The bash command is usually built like this:

[Command] [Options] [Input or path to a file or directory]

for instance:

ls -la /Applications

ls – this is a team, -la – this is a mix of two options (-l and -a), a /Applications – this is the path to the list.

Way

If you understand the way, then you will understand, how macOS actually sees your files. how? Yes, as in a nesting doll – one by one. for instance, here is the path to the file called «My secrets», lying on the desktop: /Users/…/Desktop/My Secrets.

Spaces

A simple rule applies to spaces – nothing extra!

Why? The thing is, that bash considers space as the end of a command!

If you have a folder with spaces in the name – eg, … Folder, and you are trying to display its contents with the ls command /Applications/… Folder, then the corresponding file will not be found, and an error appears on the output:

To solve this problem, need quotes or backslash. Now everything will be right:

ls /Applications/»… Folder», or ls /Applications/… Folder

Sudo

Many teams require admin access. If you are currently using a Mac not under his account «admin», but you know the password, type sudo into the command line before the text of the command itself – (which means «single user do», «makes one user»). So you temporarily get administrator privileges and the ability to perform the necessary operations without changing your account.


Terminal Commands to Improve Productivity

find

  • Replaces: Spotlight
  • Why is better: works faster, also searches for system folders (whereas Spotlight does not search for them or poorly indexes their contents).

Find syntax has four parts:

  1. find;
  2. directory path, in which you want to search for information (eg, /Applications);
  3. options (eg, -name gives find ability to search files, which match the given name);
  4. the search query itself (eg, Google Chrome).

This is what the whole team looks like:

find /Applications -d 1 -name «*Google Chrome*»

Note: «stars» (*) indicate that, what is used regex (regular expressions).

ls

  • Replaces: ⌘Cmd + I (show info).
  • Why is better: faster, can display information about several files at once and has a rich palette of settings.

ls – incredibly powerful. command to display that, what is in your folders. She also gives information about, who has the right to see them, are there any hidden files or folders on your Mac, and much more.

Best Options for ls:

-l – displays permissions for each file in a folder, last change time, file owner and his (file) title.

-a – shows all files in a folder, including hidden (great option for user library, which is hidden by default in macOS).

Here’s how it works:

ls -la /System/Library

mkdir

  • Replaces an action: Finder → File → new folder.
  • Why is better: works faster, and you can name the new daddy immediately on the command line (no need to double-click, how it takes place to be in the graphical interface).

Creates new folders in the blink of an eye.

Example:

mkdir /Users/…world/Desktop/…_Folder

rm

  • Replaces: the procedure for sending files to the Trash and cleaning it;
  • Why is better: faster, plus even those files are deleted, which usually cannot be disposed of with the help of the Recycle Bin.

This command removes absolutely any file once and for all, which you put in the team. what, of course, requires increased attention – Unlike Recycle Bin, rm will not ask «are you sure?». Supposed, What do you know, what you are doing…

Default rm deletes only files, folders remain. For, to delete them immediately, use option -R (recursively).

Example:

rm -R /Users/…world/Desktop/…_Folder