Command For Mac Terminal



Terminal User Guide

For

How many times did you have something running on your Mac and you wanted to make. Make Terminal windows stand out with profiles. When you’re logged in to several servers, unique background colors and window titles specified in profiles help you easily spot the right Terminal window. Use profiles built into Terminal, or create your own custom profiles. How to create profiles for Terminal. The command line is not only powerful, it can also be dangerous. Learn how to use commands for deleting files and folders correctly to make sure your time with Terminal is a productivity godsend.

Restart command for mac terminal

You must be an administrator or root user, also called superuser, to execute many of the commands used to manage a server.

Command For Mac Terminal

For example, if you’re not an administrator or a root user, entering the shutdown command gives you an error:

This is because the shutdown command can be run only by the root user or by an administrator user with root user privileges.

Mac terminal commands cheat sheet pdf

To run commands with superuser privileges, use the sudo command. sudo stands for superuser do.

The following example works on computers with macOS installed, so don’t run it unless you want to restart your computer:

% sudo shutdown

You’re asked for the password of the current user.

Only administrator users can use sudo. If you’re not logged in as an administrator, you can do so by entering the following command, where adminUsername is the name of an administrator user:

You’re asked to enter the password for adminUsername, after which a new shell is opened for that user.

If a command requires it, you can use su to switch to the root user. Under normal circumstances, you shouldn’t log in as the root user.

Important: If you use su to log in as the root user, be especially careful, because you have sufficient privileges to make changes that can cause your computer to stop working.

See alsoEnter a password in the Terminal window on Macsudo command man pagesu command man page

Hidden behind beautiful Mac screens is the world of Terminal Command lines. Knowing how to use these commands will help you increase your work efficiency in a great way.

Below is a list of the most basic commands divided by purpose of use:

CORE COMMANDS

Ipconfig Command For Mac Terminal

Key/CommandDescription
cd [folder]Change directory e.g. cd Documents
cdHome directory
cd ~Home directory
cd /Root of drive
cd –Previous directory
lsShort listing
ls -lLong listing
ls -aListing incl. hidden files
ls -lhLong listing with Human readable file sizes
ls -REntire content of folder recursively
sudo [command]Run command with the security privileges of the superuser (Super User DO)
open [file]Opens a file ( as if you double clicked it )
topDisplays active processes. Press q to quit
nano [file]Opens the file using the nano editor
vim [file]Opens the file using the vim editor
clearClears the screen
resetResets the terminal display

CHAINING COMMANDS

Key/CommandDescription
[command-a]; [command-b]Run command A and then B, regardless of success of A
[command-a] && [command-b]Run command B if A succeeded
[command-a] || [command-b]Run command B if A failed
[command-a] &Run command A in background

PIPING COMMANDS

Command For Mac Terminal
Key/CommandDescription
[command-a] | [command-b]Run command A and then pass the result to command B e.g ps auxwww | grep google

COMMAND HISTORY

Restart Command For Mac Terminal

Key/CommandDescription
history nShows the stuff typed – add a number to limit the last n items
Ctrl + rInteractively search through previously typed commands
![value]Execute the last command typed that starts with ‘value’
![value]:pPrint to the console the last command typed that starts with ‘value’
!!Execute the last command typed
!!:pPrint to the console the last command typed

FILE MANAGEMENT

Mac Command Line List

Key/CommandDescription
touch [file]Create a new file
pwdFull path to working directory
.Current folder, e.g. ls .
..Parent/enclosing directory, e.g. ls ..
ls -l ..Long listing of parent directory
cd ../../Move 2 levels up
catConcatenate to screen
rm [file]Remove a file, e.g. rm data.tmp
rm -i [file]Remove with confirmation
rm -r [dir]Remove a directory and contents
rm -f [file]Force removal without confirmation
cp [file] [newfile]Copy file to file
cp [file] [dir]Copy file to directory
mv [file] [new filename]Move/Rename, e.g. mv file1.ad /tmp
pbcopy < [file]Copies file contents to clipboard
pbpastePaste clipboard contents
pbpaste > [file]Paste clipboard contents into file, pbpaste > paste-test.txt

DIRECTORY MANAGEMENT

Key/CommandDescription
mkdir [dir]Create new directory
mkdir -p [dir]/[dir]Create nested directories
rmdir [dir]Remove directory ( only operates on empty directories )
rm -R [dir]Remove directory and contents
less [file]Output file content delivered in screensize chunks
[command] > [file]Push output to file, keep in mind it will get overwritten
[command] >> [file]Append output to existing file
[command] < [file]Tell command to read content from a file

SEARCH

Key/CommandDescription
find [dir] -name [search_pattern]Search for files, e.g. find /Users -name 'file.txt'
grep [search_pattern] [file]Search for all lines that contain the pattern, e.g. grep 'Tom' file.txt
grep -r [search_pattern] [dir]Recursively search in all files in specified directory for all lines that contain the pattern
grep -v [search_pattern] [file]Search for all lines that do NOT contain the pattern
grep -i [search_pattern] [file]Search for all lines that contain the case-insensitive pattern
mdfind [search_pattern]Spotlight search for files (names, content, other metadata), e.g. mdfind skateboard
mdfind -onlyin [dir] -name [pattern]Spotlight search for files named like pattern in the given directory

HELP

Mac Terminal Shortcut

Key/CommandDescription
[command] -hOffers help
[command] –helpOffers help
info [command]Offers help
man [command]Show the help manual for [command]
whatis [command]Gives a one-line description of [command]
apropos [search-pattern]Searches for command with keywords in description