Skip to content

Instantly share code, notes, and snippets.

@madhuakula
Forked from ryansechrest/terminal.md
Created October 7, 2016 17:15
Show Gist options
  • Save madhuakula/b548d76ea64667906ecc19cc98688fd4 to your computer and use it in GitHub Desktop.
Save madhuakula/b548d76ea64667906ecc19cc98688fd4 to your computer and use it in GitHub Desktop.
Shortcuts for Mac terminal.

Shortcuts

Command Description
Ctrl + A Jump to beginning of line
Ctrl + E Jump to end of line
Ctrl + U Delete text before cursor
Ctrl + K Delete text after cursor
Ctrl + W Delete word before cursor
Ctrl + T Swap last two characters before cursor
Esc + T Swap last two words before cursor
Ctrl + R Search through previous commands
Ctrl + L Clear screen (or Cmd + K)
Ctrl + C Kill current process
Ctrl + D Exit shell

Core Commands

Command Description
cd Move into home directory
cd dir Move into directory
ls List files
ls -l List files with details
ls -a List hidden files
ls -lh List files with human-readable file size
ls -R List files recursively
sudo command Run command as admin
open file Open file
open . Open current directory
top Display active processes
clear Clear screen

Command History

Command Description
history n Display last n commands
Ctrl + R Search through previous commands
!* Use arguments from previous command
!$ Use last argument from previous command
Esc + . Print arguments from previous command
!value Run previous command starting with value
!! Run previous command

File Management

Command Description
touch file Create empty file
pwd Print full path of current directory
cat file Print file to screen
rm file Remove file
rm -i file Remove file with confirmation
rm -f file Remove file without confirmation
cp file file Copy file (original → copy)
cp file dir Copy file into directory
mv file file Rename file (old → new)

Directory Management

Command Description
mkdir dir Create directory
mkdir -p dir/dir Create subdirectory
rmdir dir Remove empty directory
rm -R dir Remove directory with contents

Piping

Command Description
more Print to screen in chunks
> file Write to file
>> file Append to file
< file Read from file

Help

Command Description
[command] -h Print help
[command] --help Print help
[command] help Print help
man [command] View manual
whatis [command] Print description

Adapted from: https://github.com/0nn0/terminal-mac-cheatsheet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment