Mac Command line and how to use it

Commander logo
Top choice
Commander One 4.5 Rank based on 89+ users, Reviews(15)
avatar logo
What is Mac Command line? Command line for Mac or Terminal, is a special window into which you enter special commands to communicate with your computer’s operating system directly without a mouse. It doesn’t have a beautiful graphical interface, that is definitely more pleasant to work with but over time you get used to it and start to like it.

What can you do in Mac OS X Command line?

Using the console, you can do anything you want: copy files and text fragments, edit text documents, open and delete files, and more. The console allows you to do a lot of things that can not be done with the mouse in the graphical interface.

Command line Mac

How to open Command line Mac?

  1. Press the keyboard shortcut Command (⌘) + T.
  2. Or launch Spotlight by clicking the magnifying glass icon in the upper horizontal menu on the right.
  3. Or use the keyboard shortcut Ctrl + Space. In the Spotlight search bar, enter the word “Terminal” and press “Enter”.

As a result, Command line in Mac will open.

How to write the path to directories/files in Command line Mac

After any of the commands, you can specify the following characters to specify the desired location of the directory or file:

  • ★ . - current directory;
  • ★ .. - parent directory (one level up);
  • ★ ~ - home directory;
  • ★ / - root directory.

Tips to simplify Command line on Mac

  1. Use autocomplete for the input. For example, you can enter only the first letters of a command and press the Tab, after which the missing letters of the command will be added automatically. If there are several commands that start with the characters you have entered, then pressing Tab twice will display all these commands as a hint.

  2. Use autocomplete also for names and paths to files and directories. This function works similarly to autocomplete commands.

  3. If you press the up key ↑ in the Mac OS Command line, the last command you entered will be displayed. If you continue pressing the up key ↑, you will go through the history of the commands you have executed. The full history is stored in the file ~ / .bash_history.

  4. If you enter two exclamation marks !! and press enter, the last command entered will be executed.

  5. If you mess up when typing commands in Command line Mac OS, try pressing Control + C, this combination stops the current command as well as closes it. You can also try pressing Q and Esc.

  6. In order to read the manual for any command and find out what it does, as well as what parameters it has, you need to type man command_name.

Basic Mac Command line commands

cd ~ helps you to navigate through various directories. For example, if you decide to go to the directory where your documents are located, the following command will look like this: cd ~ / Documents

  • cd - allows you to return to the previous directory.
  • cd .. allows you to go up to the higher directory.
  • ls - lists the file names in the specified directory.
  • ls -f - shows files with their extension.
  • ls -a - lists all files, including hidden ones.
  • ls -lo - in addition to listing existing files, also shows their access rights and the date they were created. If you want to list only files starting with a particular letter. For example, with K, type: ls K*.

Note that, the command is rather case-sensitive, and if some files have the capital K at the beginning, and you typed the usual k, you simply won't see them.

  • mkdir - creates a new directory. For example, to you create a new directory called “New”, type the following command in Mac Command line: mkdir new
  • rm - allows deleting the specified file. rm new.txt.
  • rmdir - allows removing the specified directory. rmdir new.
  • rm -R - directory name if you want to delete a directory with a content.
  • rm -R new - remove the new directory with all its contents.
  • clear - clears Mac Command line screen. In principle, sometimes it is enough just to make a “right click” on the Terminal window and select Clear Scrollback from the context menu.
  • df - is a simple command that will show you the amount of your disk space, including network drives.
  • du - shows a list of all folders available on your system partition.

How to use Command line in Mac for copying

cp - allows copying files and folders. Suppose you want to copy the note.txt file from the desktop to the Documents directory. In this case, you need to type in Mac Command line: cp note.txt ~ / Documents

Please note that if a file with the same name exists in the new location, it will be deleted and replaced with the copied file without warnings and the possibility of recovery.

If you want not just to copy the file, but to copy and save it with a new name (for example, replace the new.txt with a new name), then the required command will look like this: cp note.txt ~ / Documents / new. txt

  • ditto - allows you to copy the directory, but with the attributes of hidden files.
  • mv - allows you to rename files. For example, by typing the following command in the Command line on Mac, you rename the file or directory named new to old: mv new old

Search commands in Command Line for Mac

find - search for files that match your criteria.

Examples:

  • find / -name file name: the command will search for the file you need across the entire file structure, including all mounted drives (including network drives) and display the full path to it.
  • find -x / -name file name: the same, but the search will be carried out exclusively on the boot disk of your system.
  • find. -name '* filename *': (with the specified syntax preserved) - the search will be performed in the current directory and all its subdirectories.

Mac Command line commands for processes

  • ps -x - command, issuing in the terminal a list of processes of the current user.
  • ps -ax - shows a list of all processes.
  • top - lists the main processes involved and constantly updated information about them. The load on the processor, the size of the memory involved, the time, etc.
  • kill - is a command that kills a hung process or sends a signal to it.
  • sync - is a command that forcibly writes the contents of the disk cache to the hard disk.
  • lsof - is a command that shows a list of open files on your system and files that are currently being accessed by a program.

These are the most popular Command line commands Mac which are used most often. If you are a beginner, then let them not scare you, in fact, everything is simple, you just need to get used a little. Of course, few users use the capabilities of the Terminal in everyday life. But, once you start working with Mac OS Command line, you quite quickly appreciate the opportunities that it provides you.

Try alternative Mac Command line tools

Terminal is a system command-line application for many decades. However, if you need something more, or just want something else try Commander One. It is a full-featured dual-panel file manager that in addition has a built-in Terminal emulator with all the necessary options. The key feature of the app is the ability to work without switching between the applications. You will get an interface with two panels for conveniently moving and copying files from one place to another; view multiple tabs to eliminate interference; Commander One provides a wide range of features, including the ability to connect to (S)FTP and WebDAV servers, as well as Google Drive, Dropbox, OneDrive and Amazon S3 accounts to your Mac as disks, advanced search, sorting files, setting up hotkeys, ZIP, RAR, TAR, etc. support, and many more.

Commander One

This dual panel file manager for Mac is fully compatible with MacOS 10.10 and later. Requires 36.95MB free space, latest version 2.1(3037) released 8th Jul, 2019

4.5 rank based on 89+ users, Reviews(15) , Reviews (15)
Editor's Choice
/ / / Mac Command line and how to use it