Terminal Commands

Basics

pwd - print working directory
ls - list directory contents

cd $DIR - change directory
cd .. - go up one directory mkdir $DIR - create directory touch $FILE - create file cp $FILE_1 $FILE_2 - copy one file to another. The last argument will always be the destination so one can copy multiple files at the same time
mv $FILE_1 $DIR - move files to new directory

rm $FILE - remove file

echo "String" - print to standard output

cat $FILE - output contents on file to terminal
wc - outputs the number of lines, words and characters
sort - takes sdin and sorts alphabetically
uniq - filters out adjacent, duplicate lines in file. Use in conjunction with ‘sort’ to filter out lines that are duplicate but not adjacent
grep - global regular expression print

sed s/snow/rain - stream editor. Accepts stdin and modifies it based on expression. In this example only the first match, per line, will be changed

clear - clear the current terminal display
source - activate bash profile and make it’s changes active in current session
alias something="pwd" - create an alias that runs specified command
history - print out terminal history
PS1 - environment variable that defines the style of the command prompt
env - lists environment variables set for current session

Ctrl+z - suspends a running command

macOS Tools (via Saurabh 😎)

macOS is fortunate to have access to the huge arsenal of standard Unix tools. There are also a good number of macOS-specific command-line utilities that provide unique macOS functionality. To view the full documentation for any of these commands, run man <command>.