Terminal Commands for Mac

macOS Terminal Commands

Through Terminal commands for Mac We can perform actions that, on certain occasions, are not available through the graphical interface of macOS or, the process to do so is very slow and laborious.

Terminal commands for Mac, work on all versions of macOS that has launched, practically, since the first version. If you want to start using them and get the most out of them, I invite you to continue reading.

Keep in mind that with Terminal commands for Mac you can perform changes in your team, configuration changes that may affect the operation of your equipment.

In addition, you can also delete files, create directories, find out which devices are connected to your network, perform searches...

If you already know the system commands in windows (which come from MS-DOS) it won't take you long to learn how to use the Terminal for Mac commands that we show you in this article.

How to access Terminal

access Terminal

The first thing we must do in order to start mess with the guts of macOS is to access the macOS command line. To start using Terminal commands on Mac we must perform the following steps:

  • Press the keyboard shortcut Command + space bar.
  • We write Terminal.
  • Click on the first search result.

This app is also in the Launchpad, inside the folder Others. If you like the idea of ​​working with commands, you can take a look at an article where we show you the best keyboard shortcuts for mac.

Basic Terminal Commands

[table]

,,

/ (Forward Slash),Top level directory

.,Current directory

..,Top directory

~,Home directory

sudo [command], Run command with root security privileges

nano [file],Opens the Terminal editor

open [file],Open a file

[command] -h, Get help on a command

man [command],Displays the help manual for the command

,,

[/ Table]

Terminal Search

[table]

,,

find -name <«»file»»>»,Finds all files named within . We can use asterisks (*) to search for parts of file names

"grep" »» »,Search for all matches of within

"grep -rl "" »» »,Search for all files containing within

,,

[/ Table]

Management of Terminal Permits

Terminal permissions

[table]

,,

ls -ld, Show the default permission of a source directory

ls -ld/ ,Displays read permissions; write and access a certain folder

chmod 755 ,Change the permission of a file to 755

chmod -R 600 ,Change the permission of a folder and all its contents to 600

chown : ,Changes the ownership of a file to user and group If we add the command “-R” the contents of the folder will be included

,,

[/ Table]

File size and disk space

[table]

,,

du,Using the list for each subdirectory and its contents

du -sh [folder], Readable output of all files in a directory

du -s,Show an entry for each specified file

du-sk* | sort -nr List files and folders (summarizing size including subfolders). We can substitute sk* for sm* to list the directories in MB

df -h,Displays the free disk space of your system

df -H, Calculate free disk space in powers of 1.000 (instead of 1.024)

,,

[/ Table]

Management of files and directories

[table]

,,

mkdir ,Create a new folder called

mkdir -p / ,Create nested folders

mkdir ,Create multiple folders at once

"mkdir"" »»»,Creates a folder with a space in the file name

rmdir ,Deletes a folder (only works with empty folders)

rm -R ,Deletes a folder and its contents

touch ,Create a new file without any extension

cop ,Copy a file to the folder

cop ,Copy a file in the current folder

cop ~/ / ,Copy a file in the folder and rename the copied file

"cp -R <«»new dir»»>»,Copy a folder to a new folder with spaces in the file name

cp -i ,Warns you before copying a file with an overwrite warning message

cop /Users/ ,Copy several files in a folder

ditto -V [folder path][new folder],Copies the contents of a folder to a new folder. The "-V" command displays a status line for each file copied.

rm ,deletes a file permanently

rm -i ,Deletes a file requesting confirmation

rm -f ,Force unconfirmed deletion of a file

rm ,Delete multiple files without confirmation

mv ,move/rename

mv ,Moves a file to the folder (overwriting the existing file with the same name if it exists)

mv -i ,The "-i" command displays a warning that it is going to overwrite the destination file.

mv*.png ~/ ,Move all PNG files in the current folder to a different folder

,,

[/ Table]

Managing directories with Terminal

[table]

,,

cd, home directory

cd [folder],Change directory

cd ~,Home directory

cd/,root of the drive

cd -,Previous directory or folder that you last browsed

pwd, show working directory

cd..,Go up to parent directory

cd../..,Up two levels

,,

[/ Table]

Listing files and directories with Terminal

Terminal files and directories

[table]

,,

ls,Display the name of the files and subdirectories of the directory

ls -C,Show the name of the files and subdirectories of the directory in columns

ls -a,List all entries (including those with .(dot) and ..(double dot))

ls -1,Display the list of files in one entry per line format

ls -F, Display a / (slash) immediately after each path that is a directory

ls -S Sort files or entries by size

ls -l,Long format list. Includes file mode; the name of the owner and the group; the date and time the file was modified; the name of the route; etc

ls -l /,List filesystem from root with symlinks

ls -lt, List of files sorted by modification time (most recent first)

ls -lh,Long listing with readable file sizes in KB; MB or GB

ls -lo,List filenames with size; owner and flags

ls -la,Detailed list of directory contents (including hidden files)

,,

[/ Table]

Keyboard shortcuts in Terminal

[table]

,,

Tab,Autocomplete file and folder names

Ctrl + A, Go to the beginning of the line you are typing on

Ctrl + E, Go to the end of the line you are typing on

Ctrl + U, Delete the line before the cursor

Ctrl + K, Delete the line after the cursor

Ctrl + W, Delete the word before the cursor

Ctrl + T, Swap the last two characters before the cursor

Esc + T, Swap the last two words before the cursor

Ctrl + L, Clear screen

Ctrl + C, stop whatever is running

Ctrl + D, Exit current shell

Option + →,Move the cursor one word forward

Option + ←,Move the cursor back one word

Ctrl + F, Move the cursor one character forward

Ctrl + B, Move the cursor one character back

Ctrl + Y, Paste what was cut by the last command

Ctrl + Z, Put what is running into a suspended background process

Ctrl + _, Undo the last command

Option + Shift + Cmd + C, Copy plain text

Shift + Cmd + V, Paste the selection

exit,End a shell session

,,

[/ Table]

Command history

[table]

,,

Ctrl + R,Search for previously used commands

history,Shows the commands that we have written previously

![value],Run the last used command that starts with a value

!!, Execute the last used command

,,

[/ Table]

Terminal Processes

terminal processes

[table]

,,

ps -ax Shows the processes that are currently running. The "a" command displays all user processes and the "x" command displays processes that are not connected to the Terminal

ps -aux,Show all processes with %cpu; %mem; page-in and PID

top,Shows real-time information about the processes that are running

top -ocpu -s 5,Shows processes sorted by CPU usage and updating every 5 seconds

top -o rsize, Sort processes by memory usage

kill PID, Exit process with ID . The PID will be displayed as a column in the Activity Monitor

ps -ax | grep ,Search for a process by name or PID

,,

[/ Table]

Network commands in Terminal

[table]

,,

ping ,Ping the host and display its status

whois ,Obtain whois information of a domain

curl -O ,Downloads a file via HTTP; HTTPS or FTP

ssh @ ,Establish an SSH connection to with the user

scp @ :/remote/path,Copy still remote

arp -a Displays a list of all devices on your local network including the IP and MAC addresses of all devices

ifconfig en0,Displays the IP and MAC address of your device

traceroute [hostname], Identifies the path and hops traversed by packets from your device to the destination address

,,

[/ Table]

Homebrew

[table]

,,

brew doctor,Check system for potential problems

brew help,List of useful Homebrew commands

brew install | ,Install a formula

brew uninstall |cask>,Uninstall a formula

brew list --formula,List only installed formulas

brew deps | ,List all dependencies of a formula

brew search text|/regex/,Search formulas using regex

brew upgrade | ,Update the formula

brew outdated | ,Search formula

brew outdated –formula,Find an outdated formula

brew pin [installed_formula],Pin a formula so it doesn't update

brew unpin [installed_formula],Unpin to update a package

brew cleanup,Remove lock files and outdated packages from all formulas

,,

[/ Table]

Environment variable or path

[table]

,,

printenv,Displays a list of currently set environment variables

echo $PATH,Check the value of the PATH variable that stores a list of directories with executable files

echo $PATH >path.txt,Exports the path directory to a text file

export PATH=$PATH:absolute/path to/program/,Run a program through the terminal in the current session only.

,,

[/ Table]


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Actualidad Blog
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.