Terminal Cheat Sheet Mac

  



The Terminal on macOS offers quite an amount of functionality, but most of it is hard to discover unless you already know what you’re looking for. So here’s a quick cheat sheet explaining unique functions with their corresponding key combos:

A complete Terminal cheat sheet for everyday use. (from beginners to advanced users). About the Content. Everything you will ever need to know about the terminal and to make use of the command-line interface efficiently. ⇒ In Finder → select the Go menu → use the mac Spotlight → search Terminal. Terminal Cheat Sheet All the knowledge you need to get up and running on terminals across operating systems. An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX) alias Create an alias alloc List used and free memory awk Find and Replace text within file(s) basename Convert a full pathname to just a folder path bash Bourne-Again SHell (Linux). The Mac Terminal Commands Cheat Sheet - With so many Mac commands, it’s often difficult to remember and use them all. We’re here to help with a detailed cheat sheet of Mac Terminal commands you can use to unlock enhanced productivity on your system. #Mac #MacBook #macOS #Apple #Terminal #Commands #Guide #CheatSheet.

Marks

Marks allow you to mark certain lines in the output, and allow you to jump between different parts of the output.

By default, every time you hit enter on your prompt, Terminal will automatically insert a mark for you. You can configure this in the Edit menu, under Marks with the option Automatically Mark Prompt Lines.

Mac

Marks are visualised in the Terminal window as light grey square brackets (They are not, however, part of the output).

  • Cmd-⬆: Jump to previous mark
  • Cmd-⬇: Jump to next mark
  • Cmd-Shift-A: Selects the output between the current marks
  • Cmd-Enter: Enter, and will always create a mark
  • Cmd-Shift-Enter: Enter, but will never create a mark
  • Cmd-U: Create mark
  • Cmd-Shift-U: Remove mark
  • Cmd-L: Clear screen to previous mark

Bookmarks

Similar to marks, they can optionally be named, and are more useful to denote larger sections of the output. They are denoted by light grey bars.

  • Cmd-Shift-M: Insert Bookmark
  • Cmd-Option-U: Mark current line as bookmark
  • Cmd-Shift-Option-M: Insert named bookmark
  • Cmd-Option-⬆: Jump to previous bookmark
  • Cmd-Option-⬇: Jump to next bookmark
  • Cmd-Option-L: Clear to previous bookmark

Panes

View different parts of the scrollback buffer of the same terminal.

  • Cmd-D: Split window into panes
  • Cmd-Shift-D: close split pane

Miscellaneous

  • Cmd-K: Clear everything
  • Cmd-Option-K: Clear scroll back (everything except what you see on the screen)
  • Cmd-Option-O: Toggle use of option as meta key
  • Cmd-Ctrl-V: Paste escaped text. Useful for pasting e.g. paths containing whitespace.
  • Cmd-Shift-Option-C: Copy as plain text
  • Cmd-Option-PageUp or PageDown: Scroll one line up/down
  • Cmd-[ or ]: Switch between windows
  • Cmd-Shift-[ or ]: Switch between tabs

(Some of this I learned from mjtsai’s post Mac Terminal Tips, which is a great jumping off point for further interesting things the Terminal can do)

What is a Terminal on Mac

As it turned out, huge amounts of search queries concerning the topic “Terminal on Mac”, “Mac hacks Terminal” appear on the Internet almost every day. Moreover, many people want to find out how to run Terminal in the Apple operating system. As it is well known, a regular user has no reason to use or even open Terminal, an Apple Command Line interface application, but it’s worth a try because, in fact, it gives access to many tricks and shortcuts. So, let’s start.

It is a well - known fact that Apple has its own Mac Command Line interface, in which you can easily and quickly manage tasks than perform a normal and long process. However, its interface looks rather specific, especially if you do not have the technical knowledge or any clue how to use the Terminal on Mac. However, once you take a look at this useful application, you will surely like it. Who knows?

Terminal is a standard system utility for interacting with Mac using the Command Line. Linux has a similar management tool because both operating systems are Unix-like. In brief, all you need to know about the Terminal is that it is an application that allows you to control your computer using commands, besides that opens the possibility to work with locked functions, etc.

How to open Terminal on Mac

For the record, there are several ways to open Mac Terminal. Choose the one that meets your requirements the most.

1. How to open Command Line on Mac via the Dock

There is usually “Applications” shortcut on the Dock panel on macOS. Click on it and a list of all installed programs on your Mac will be open. Find and open the “Utilities” folder, inside you will find the “Terminal” app. Run it. Please note that in recent versions of Mac OS X, this shortcut is called Launchpad.

2. Opening Terminal through the Finder

Open Finder (in the Dock it is always on the left). In the left menu, select 'Applications' and in the list of all programs that open, find the directory/folder 'Utilities'. Click on it and search for the application 'Terminal.app' in it. Double-click the Terminal.

3. Opening Terminal on Mac through the Spotlight search bar

Hold down the Ctrl + Spacebar key combination at the same time. In the pop-up window, enter the word 'Terminal'. Once you have typed you will see the application you need, all you need is just click it.

4. Basic Terminal Mac shortcuts

  • Command (⌘) + T is used in order to open a new terminal window.
  • Command (⌘) + N is used in order to open a new tab in the terminal.
  • Command (⌘) + Shift + [ and Command (⌘) + Shift + ] are used to switch tabs back and forth.

Mac Terminal tricks you should know

Mac OS Terminal can do a lot, from moving a lot of files to changing preferences that we couldn't even think of. To demonstrate what Terminal can do, we have put together 11 really excellent tips and tricks that you might find useful.

1. Enable showing hidden files and folders

If you want to see all the folders and files hidden by the system, then run the following command in the Terminal:defaults write com.apple.finder AppleShowAllFiles -bool TRUEkillall finder
Tip: To hide them back, change the value from TRUE to FALSE.

2. View the contents of any files

If you have a damaged file or you suspect that something else is hidden inside it, then you can force the Terminal to open it, despite the failure of normal applications, with the corresponding command:cat ~ / path / to / file
Be careful, if you try to open a photo or any other non-text document, you will see a wall of illegible characters.

3. Copy the contents of a folder from one location to another

Of course, you can just copy-paste the entire contents of the folder, but in cases where you need to simplify and / or automate this process, the following Mac Terminal command will help you: ditto -V ~ / source / folder / ~ / new / folder /

4. Changing the file format of screenshots

While using Terminal on Mac, you can change the format of screenshots from .PNG to any other, including PDF and JPG.defaults write com.apple.screencapture type jpg

5. Disable shadows in screenshots

Those who take a lot of screenshots and want nothing extra on them can turn off the drop shadow effect and leave only the window itself being shot. defaults write com.apple.screencapture disable-shadow -bool TRUEkillall SystemUIServer

6. New names for screenshots

I absolutely do not like that boring and inconvenient format for the names of screenshots (“Screenshot date-time”), so below there will be a command that allows you to replace the word “Screenshot” with something more appropriate.defaults write com.apple.screencapture name 'New name'killall SystemUIServer
By the way, to return the setting to the original name, you need to enter this:defaults write com.apple.screencapture name 'killall SystemUIServer

7. New folder for screenshots

By default, all screenshots are saved to your desktop, clogging up valuable space. To change this, simply enter the following command from the list of Useful Terminal commands:defaults write com.apple.screencapture location ~ / your / location / herekillall SystemUIServer

8. Your own greeting in the login window

Using a special command, you can place your own message on the login screen. You might want to write something funny and original, or leave your phone number in case your Mac goes missing.sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText 'Somebody told me there is a place where everything is better and everything's safe.'

9. How long has my Mac been on?

When was the last time you have rebooted your computer? You can check this with a command in the Terminal:uptime

10. Disable sleep mode

Sometimes it becomes necessary to keep the Mac awake, for example, when downloading a torrent or creating a backup. While using Mac Terminal you can disable hibernation on your Mac by typing:caffeinate
Now your Mac will not fall asleep under any pretext.

Tip: For this command, you can specify the time (in seconds) after which the Mac will automatically go to sleep if it is inactive.caffeinate -u -t 5400

11. Start auto-restart when the Mac completely freezes

Of course, it also happens: for no reason at all, the Mac freezes and you have nothing left but a forced reboot. The following command forces OS X to reboot if it realizes that the system is not responding:
sudo systemsetup -setrestartfreeze on

Terminal Mac Commands List to improve productivity

find

Replaces: Spotlight. Why it is better: works faster, searches for system folders (while Spotlight does not search or index their content poorly) So if you want to know how to navigate to a folder in Terminal Mac, this command can help you:
find / Applications -d 1 -name '* Google Chrome *'

The find syntax consists of four parts:

  • find;
  • the path to the directory in which you want to look for information;
  • options;
  • search itself.

du

Replaces: ⌘Cmd + I. Why it is better: can show multiple folders at once, and usually run faster.

du is a reduction from 'disk usage'. This Mac Terminal command will help you quickly find out the size of a specific file or folder, or even a list of files inside a folder. The best options for du:

-d (depth): if there is a number behind that letter, then find will limit the search to the directory by the appropriate number of levels. For example:
-d 1 / Applications

Terminal will only give you information about the general size of folders and files in the Applications folder, without the data on the size of subfolders embedded in those folders.

-h (human readable). Displays the size of files in common values ​​- K (kilobytes), M (megabytes) or G (gigabytes).

mv

Mac Os Terminal Cheat Sheet

Replaces: manual transfer of folders and files in the right place. Why it is better: faster and does not require a lot of manual work.

The mv syntax is very simple - the old path changes to a new one:mv / Users / Maria / Documents / file1 / Users / Maria/ Desktop / file1

This Terminal Mac command transfers file1 from the Documents folder to the Desktop.

ls

Replaces: ⌘Cmd + I. Why it is better: faster, able to display information about several files at once, and has a rich palette of settings.
ls -la / System / Library

ls

Examples Of Cheat Sheets

provides information about who has the right to see files, whether there are hidden files or folders on your Mac, etc. The best options for ls:
  • -l - displays the rights for each file in the folder, the last modification time, the owner of the file, and its (file) name.
  • -a - shows all files in the folder, including hidden ones.

mkdir

Replaces the action: Finder → File → New folder. Why it is better: it works faster, and you can immediately enter the name of the new folder on the command line.

Creates new folders in no time. Example:mkdir / Users / Maria/ Desktop / Maria_Folder

rm

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

This Mac Terminal command deletes absolutely any file that you put in the Command Line. By default, rm only deletes files, folders remain. To remove them immediately, use the -R option. Example: rm -R / Users / Maria / Desktop / Maria_Folder

Mac App Store version: Available here

This FTP Terminal would be a cup of tea for those who want to keep everything under control and within reach. Commander One isn't just a decent Terminal emulator app for Mac but also a rather functional file manager. To execute Terminal commands Mac users need first of all to invoke Terminal in Commander One by pressing simultaneously the combination CTRL + O, and after that follow the above Mac Terminal commands cheat sheet.


Once everything is done, you can return to the previous mode of Commander One by pressing the mentioned above hotkey. Besides that, the app has a lot of other features that can surprise the user, such as copying, deleting, compressing and uncompressing files, connecting to FTP servers, mounting popular cloud storages as local drives, mounting MTP and iOS devices, viewing processes in the system, etc.

The most remarkable that is worth to be mentioned is the incredible speed at which the app performs all the actions.

Mac Terminal Commands

Conclusion

Remember that Terminal is not a completely safe thing. An inexperienced user can do some kind of trouble. Before executing any Mac Terminal commands, check your knowledge with the Geeks on the Internet, do not take on excessive risk. This advice also applies to courageous people who want to roll back the Mac OS update without having enough information about the procedure.

However, we hope that this article was rather informative for you and you found something interesting in it.