Ga door naar hoofdinhoud

Inhoudsopgave

Basics

CommandAction
/Top level directory
.Current directory
..Parent directory
~Home directory
sudo [any command]Run a command with the security privilege of a super user
nano [file]Opens the Terminal editor
open [file]Opens a file
[command] -hGet help about a command
man [command]Show the help manual for a command

Key Combination Shortcuts

CommandAction
TabAuto-Complete file and folder names
Ctrl + AGo to the beginning of the line that you are currently typing on
Ctrl + EGo to the end of the line that you are currently typing on
Ctrl + UClear the line before the cursor
Ctrl + KClear the line after the cursor
Ctrl + WDelete the word before the cursor
Ctrl + TSwap the last two characters before the cursor
Esc + TSwap the last two words before the cursor
Ctrl + LClear the screen
Ctrl + CKill any Unix program that is running
Ctrl + DExit the current shell
Option + Right KeyMove the cursor forwards one word
Option + Left KeyMove the cursor backwards one word
Ctrl + FMove the cursor one character forwards
Ctrl + BMove the cursor one character Backwards
Ctrl + YPaste whatever was cut by the previous command
Ctrl + ZMake your running process into a suspended background process
Ctrl + _Undo the previous command
Option + Shift + Cmd + CCopy plain text
Shift + Cmd + VPaste the selection
exitEnd a shell session

Change Directory

CommandAction
cdHome directory
cd [folder]Change directory, e.g. cd Documents
cd ~Home directory
cd/Root of the drive
cd -Previous directory or folder you last browsed
pwdShow your working directory
cd ..Move up to the parent directory
cd../..Move up two levels

List Directory Contents

CommandAction
lsDisplay the name of files and subdirectories in the directory
ls -CForce multi-column output of the listing
ls -aList all entries including those with . and ..
ls -1Output the list of files in one entry per line format
ls -FDisplay a / immediately after each path that is a directory, * after executable programs or scripts, and @ after a symbolic link
ls -SSort files or entries by size
ls -lList in a long format. Includes file mode, owner and group name, date and time file was modified, pathname, and more
ls -l /List of the file system from root with symbolic links
ls -ltList the files sorted by time modified (most recent first)
ls -lhLong listing with human readable file sizes in KB, MB, or GB
ls -loList the file names with size, owner, and flags
ls -laList detailed directory contents, including hidden files

File size and disk space

CommandAction
duList usage for each subdirectory and its contents
du -sh [folder]Human readable output of all files in a directory
du -sDisplay an entry for each specified file
df -hCalculate your system's free disk space
df -HCalculate free disk space in powers of 1,000

File and Directory Management

CommandAction
mkdir <dir>Create new folder named <dir>
mkdir -p <dir>/<dir>Create nested folders
mkdir <dir1> <dir2> <dir3>Create several folders at once
mkdir "<dir>"Create a folder with a space in the filename
rmdir <dir>Delete a folder (only works on empty folders)
rm -R <dir>Delete a folder and its contents
touch <file>Create a new file without any extension
cp <file> <dir>Copy a file to the folder
cp <file> <newfile>Copy a file to the current folder
cp <file>~/<dir>/<newfile>Copy a file to the folder and rename the copied file
cp -R <dir> <"new dir">Copy a folder to a new folder with spaces in the filename
cp -i <file><dir>Prompts you before copying a file with a warning overwrite message
cp <file1> <file2> <file3>/Users/<dir>Copy multiple files to a folder
ditto -V [folder path][new folder]Copy the contents of a folder to new folder. In here "-V" print a line of status for every file copied
rm <file>Delete a file (This deletes the file permanently; use with caution.)
rm -i <file>Delete a file only when you give confirmation
rm -f <file>Force removal without confirmation
rm <file1> <file2> <file3>Delete multiple files without any confirmation
mv <file> <newfilename>Move/rename
mv <file> <dir>Move a file to the folder, possibly by overwriting an existing file
mv -i <file> <dir>Optional -i flag to warn you before overwriting the file
mv *.png ~/<dir>Move all PNG files from current folder to a different folder

Command History

CommandAction
Ctrl + RSearch through previously used commands
history nShows the previous commands you've typed. Add a number to limit to the last n items
![value]Execute the last command typed that starts with a value
!!Execute the last command type

Permissions

CommandAction
ls -ldDisplay the default permission for a home directory
ls -ld/<dir>Display the read, write, and access permission of a particular folder
chmod 755 <file>Change the permission of a file to 755
chmod -R 600 <dir>Change the permission of a folder (and its contents) to 600
chown <user>:<group> <file>Change the ownership of a file to user and group. Add -R to include folder contents

Processes

CommandAction
ps -axOutput currently running processes. Here, a shows processes from all users and x shows processes that are not connected with the Terminal
ps -auxShows all the processes with %cpu, %mem, page in, PID, and command
topDisplay live information about currently running processes
top -ocpu -s 5Display processes sorted by CPU usage, updating every 5 seconds
top -o rsizeSort top by memory usage
kill PIDQuit process with ID <PID>. You'll see PID as a column in the Activity Monitor

Network

CommandAction
ping <host>Ping host and display status
whois <domain>Output whois info for a domain
curl -O <url/to/file>Download file via HTTP, HTTPS, or FTP
ssh <username>@<host>Establish SSH connection to <host> with user <username>
scp <file><user>@<host>:/remote/pathCopy <file> to a remote <host>
arp -aView a list of all devices on your local network. It will show you the IP and MAC address of all the devices
ifconfig en0View your device IP and MAC address
traceroute [hostname]Identify the path and the hops traversed by the packets from your device to the destination address

Homebrew

CommandAction
brew doctorCheck brew for potential problems
brew helpList of useful homebrew formula and cask commands
brew list --formulaList only installed formulas
brew list --caskList only installed cask
brew outdated --formulaSearch for outdated formula
brew outdated --caskSearch for outdated cask
brew pin [installed_formula]Pin a formula from getting upgraded
brew unpin [installed_formula]Unpin to upgrade a package
brew cleanupRemove stale lock files and outdated packages for all formula and casks.

Environment Variable or Path

CommandAction
printenvDisplay a list of currently set environment variables. Also tells you which shell you're using
$echoTells the terminal to print something and show it to you
echo $PATHCheck the value of the PATH variable which storea a list of directories with executable files
echo $PATH >path.txtExport the path directory to a text file
export PATH=$PATH:absolute/path to/program/Execute a program via terminal only in your current session
CommandAction
find <dir> -name <"file">Find all files named <file> inside <dir>. Use wildcards (*) to search for parts of filenames
grep "<text>" <file>Output all occurrences of <text> inside <file> (add -i for case insensitivity)
grep -rl "<text>" <dir>Search for all files containing <text> inside <dir>

Output

CommandAction
cat <file>Output the content of <file>
less <file>Output the contents of <file> using the less command that supports pagination and more
head <file>Output the first 10 lines of <file>
<cmd> > > <file>Appends the output of <cmd> to <file>
<cmd> > <file>Direct the output of <cmd> into <file>

Jacob Mehnert

Lid sinds: 10/18/21

39.746 Reputatie

50 handleidingen geschreven

Team

iFanatics Lid van iFanatics

Community

61 Leden

196 handleidingen geschreven

0 opmerkingen

Voeg opmerking toe

Weergavestatistieken:

Afgelopen 24 uren: 5

Afgelopen 7 dagen: 50

Afgelopen 30 dagen: 184

Altijd: 10,449