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

Terminal on Mac (macOS): what is it, commands, syntax – a clear guide for beginners All Apple NEWS

Today, all of us in 99% of cases work with Mac through a nice, intuitive and convenient graphical user interface. But when solving a number of specific tasks, even Finder will not cope with what the good old command line will do …

♥ BY TOPIC: How to configure macOS without Terminal in detail: 4 useful utilities.

For example, using it is much easier – and faster! – search for a 5-gigabyte file that has been lost somewhere in the bowels of the system or the path to an application that you thought was deleted long ago.

What is a “Terminal”?

Terminal is a standard system utility for interacting with Mac using the command line. Linux has a similar management tool since both are Unix-like.

The command line interface (command line interface or abbreviated CLI) – it is the language of communication with the Terminal – called bash. All that we discuss below are bash commands.

♥ BY TOPIC: How to open a complete list of Terminal commands in macOS with a description.

Common Commands for Mac

Basic syntax

The bash command is usually built like this:

[Команда] [Опции] [Ввод или путь к файлу или директории]

For instance:

ls -la /Applications

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

♥ BY TOPIC: 10 useful Terminal commands on Mac (macOS).

Way

If you understand the path, you will also understand how macOS actually sees your files. How? Yes, as in a nesting doll – one after another. For example, here is the path to a file called “My Secrets” on the desktop: / Users / Yablykworld / Desktop / My Secrets.

♥ BY TOPIC: Mac for Dummies: 30 helpful macOS tips for beginners.

Spaces

A simple rule applies to spaces – nothing more!

Why? The fact is that bash considers a space to be the end of a command!

If you have a folder with spaces in the name – for example, Yablyk Folder, and you try to display its contents using the command ls / Applications / Yablyk Folder, then the corresponding file will not be found, and an error will appear on the output:

Terminal on Mac (macOS): what is it, commands, syntax

To solve this problem, you will need quotation marks or backslash. Now everything will be correct:

ls /Applications/"Yablyk Folder", or
ls /Applications/Yablyk Folder

♥ BY TOPIC: How to change the icon of an application, folder or file on Mac (macOS).

Sudo

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

♥ BY TOPIC: Find out the installation date for all macOS updates and apps on Mac.

Terminal Commands to Improve Productivity

find

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

The find syntax has four parts:

1. find;

2. The path to the directory in which you want to search for information (for example, / Applications);

3. options (e.g. -name gives find the ability to search for files that match the given name);

4. The search query itself (for example, Google Chrome).

Here’s what the whole team looks like:

find /Applications -d 1 -name "*Google Chrome*"

Note: Asterisks (*) indicate that regex (regular expressions) is being used.

♥ BY TOPIC: How to quickly search files on macOS without Terminal, or how Mac search works.

du

  • Replaces: ⌘Cmd + I, i.e. commands for displaying information;
  • Why is it better: can show several folders at once at a time, and usually runs faster.

du Is an abbreviation for “disk usage”. The command will help you quickly find out the size of a specific file or folder, or even a list of files inside a folder.

Top options for du:

-d (“Depth”, or depth): if there is a number behind this letter, then find will limit the directory search to the appropriate number of levels. For example, if you give your Mac a command du:

-d 1 /Applications

The terminal will give you information only about the total “weight” of folders and files in a folder Applications, without data on the size of subfolders nested in these folders.

-h (human readable, or “human readable”). Displays the file sizes in the usual values ​​for people – K (kilobytes), M (megabytes) or G (gigabytes).

Du team in action:

Terminal on Mac (macOS): what is it, commands, syntax

ON THIS TOPIC: Features of the ⌥Option (Alt) key on Mac (macOS) that you might not be aware of.

mv

  • Replaces: Manual transfer of folders and files to the desired location.
  • Why is it better: faster and does not require a lot of manual labor.

Syntax mv very simple – the old path changes to a new one:

mv .

Example:

mv /Users/Yablykworld/Documents/file1 /Users/Yablykworld/Desktop/file1

This command transfers file1 from the folder Documentation on the Desktop.

♥ BY TOPIC: How to hide files and folders on Mac (macOS) from strangers: 3 ways.

ls

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

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

Best options for ls:

-l – Displays the rights for each file in the folder, the time of the last change, the owner of the file and its (file) name.

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

Here’s how it works:

ls -la /System/Library

Terminal on Mac (macOS): what is it, commands, syntax

♥ BY TOPIC: How to take a screenshot (screenshot) on Mac – 4 ways + new tools in macOS Mojave.

mkdir

  • Replaces the action: Finder → File → New Folder.
  • Why is it better: it works faster, and you can set the name of the new daddy immediately on the command line (there is no need to double-click, as it takes place in the graphical interface).

Creates new folders in no time.

Example:

mkdir /Users/Yablykworld/Desktop/Yablyk_Folder

♥ BY TOPIC: How to find out the date of the last clean macOS installation on your Mac.

rm

  • Replaces: the procedure for sending files to the Trash and cleaning it;
  • Why is it better: faster, plus even those files that you usually cannot get rid of using the Recycle Bin are deleted.

This command once and for all deletes absolutely any file that you put in the command. Which, of course, requires increased attention – unlike the Basket, rm She won’t ask, “Are you sure?” It is assumed that you know what you are doing …

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

Example:

rm -R /Users/Yablykworld/Desktop/Yablyk_Folder

See also:

Rate article
( No ratings yet )
Share to friends
JuicyAppleNews
Leave a Reply