Git Product home page Git Product logo

terminal-mac-cheatsheet's Introduction

Terminal Cheatsheet for Mac (Basics)

This cheatsheet is available in many languages. Since the translation rely on volunteers, the content between the available languages may vary. Choose one below:

English Version

Letters are shown capitalized for readability only. Capslock should be off.


SHORTCUTS

Key/Command Description
Ctrl + A Go to the beginning of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
Ctrl + E Go to the end of the line you are currently typing on. This also works for most text input fields system wide. Netbeans being one exception
Ctrl + L Clears the Screen
Cmd + K Clears the Screen
Ctrl + U Cut everything backwards to beginning of line
Ctrl + K Cut everything forward to end of line
Ctrl + W Cut one word backwards using white space as delimiter
Ctrl + Y Paste whatever was cut by the last cut command
Ctrl + H Same as backspace
Ctrl + C Kill whatever you are running. Also clears everything on current line
Ctrl + D Exit the current shell when no process is running, or send EOF to a the running process
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it
Ctrl + _ Undo the last command. (Underscore. So it's actually Ctrl + Shift + minus)
Ctrl + T Swap the last two characters before the cursor
Ctrl + F Move cursor one character forward
Ctrl + B Move cursor one character backward
Option + → Move cursor one word forward
Option + ← Move cursor one word backward
Esc + T Swap the last two words before the cursor
Esc + Backspace Cut one word backwards using none alphabetic characters as delimiters
Tab Auto-complete files and folder names

CORE COMMANDS

Key/Command Description
cd [folder] Change directory e.g. cd Documents
cd Home directory
cd ~ Home directory
cd / Root of drive
cd - Previous directory
ls Short listing
ls -l Long listing
ls -a Listing incl. hidden files
ls -lh Long listing with Human readable file sizes
ls -R Entire 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 )
top Displays active processes. Press q to quit
nano [file] Opens the file using the nano editor
vim [file] Opens the file using the vim editor
clear Clears the screen
reset Resets the terminal display

CHAINING COMMANDS

Key/Command Description
[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

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

COMMAND HISTORY

Key/Command Description
history n Shows the stuff typed – add a number to limit the last n items
Ctrl + r Interactively search through previously typed commands
![value] Execute the last command typed that starts with ‘value’
![value]:p Print to the console the last command typed that starts with ‘value’
!! Execute the last command typed
!!:p Print to the console the last command typed

FILE MANAGEMENT

Key/Command Description
touch [file] Create a new file
pwd Full 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
cat Concatenate 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
pbpaste Paste clipboard contents
pbpaste > [file] Paste clipboard contents into file, pbpaste > paste-test.txt

DIRECTORY MANAGEMENT

Key/Command Description
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/Command Description
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

Key/Command Description
[command] -h Offers help
[command] --help Offers 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

GIT

For Git related commmands you can check my git-basics-cheatsheet

terminal-mac-cheatsheet's People

Contributors

0nn0 avatar alexwilkerson avatar bashu avatar bear29ers avatar chemfind avatar chemhding avatar codycodeman avatar codyschrank avatar daeungod avatar durul avatar enderahmetyurt avatar gnitoahc avatar hatarist avatar joelibaceta avatar kestory avatar kilianevers avatar larrybattlework avatar matthieu-malyga avatar mrvitaly avatar recepinanc avatar roxhens avatar samarism avatar theotherjonjanes avatar tian3rd avatar toankid1412 avatar vadeg avatar victor-li avatar xugy0926 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terminal-mac-cheatsheet's Issues

Consider adding 'chmod +x [file]'

I seem to use chmod quite a bit.

Command Description
chmod [options] mode[,mode] file1 [file2 ...] Change the access permissions to file system objects
chmod +x [file] Allow file to be executed

Example

Allow file to be executed

chmod +x file.sh

File Contents

#!/bin/bash
printf "chmod Rocks! \n\n";

Execute file from the command line

./file.sh

Output

chmod Rocks!

Consider adding tar, gzip, bzip2, zip

Command Description
tar -zcvf [.tgz-file] [files] Zip files with gzip compression
tar -jcvf [.tbz2-file] [files] Zip files with bzip2 compression
gzip -f -9 [file] Zip file
tar -zxvf [.tgz-file] Decompress file
tar -jxvf [.tbz2-file] Decompress file

Examples

Compress

timestamp=`date +%Y-%m-%d`
tar -zcvf archive.$timestamp.tar.gz myFolder
tar -zcvf data.tgz *.doc
tar -zcvf pics.tar.gz *.jpg *.png
tar -jcvf data.tbz2 *.doc
ls -l
gzip mydata.doc
gzip *.jpg
ls -l
bzip2 mydata.doc
bzip2 *.jpg
ls -l
zip mydata.zip mydata.doc
zip data.zip *.doc
ls -l

Decompress

tar -zxvf data.tgz 
tar -zxvf pics.tar.gz *.jpg
tar -jxvf data.tbz2
gzip -d mydata.doc.gz
gunzip mydata.doc.gz
bzip2 -d mydata.doc.bz2
gunzip mydata.doc.bz2
unzip file.zip
unzip data.zip resume.doc

Links

Bash Zip CheatSheet

Consider adding $variables

Command Description
[variable]=[value] Set variable equal to value
[command] $[variable] Use variable's value by adding $ before the name

Examples

x=12345
echo $x
timestamp=`date +%Y-%m-%d`
echo $timestamp;
hello=hello;
world=world;
echo $hello $world

Consider adding grep

Consider adding grep

Command Description
grep [search_pattern] [file] Search for all lines that contain the pattern
grep -v [search_pattern] [file] Search for all lines that do not contain the pattern
[string] grep [search_pattern]

Examples

Contents of filename.txt

a/b/c
a/b/c.zip

Search File Contents

# find all lines that contain "a/b/c"
grep "a/b/c" filename.txt

# find all lines that contain "a/b/c" or print if none are found.
grep "a/b/c" filename.txt || printf "\nNo Matches Found.\n"

# find all lines that contain "a/b/c" and do not include ".zip"
grep "a/b/c" filename.txt | grep -v ".zip"

Search Command History

# find all lines in bash history that contain the search_pattern
history | grep search_pattern

typo

grep -r [search_pattern] [file] Recursively search for all lines that do not contain the pattern

should be

lines that contain the pattern

Option + → and Option + ←

It seems that at least since macOS Sierra Option + → and Option + ← are equivalent to ESC then F and ESC then B.

Since they are easier to use it may be worth documenting them as well.

Add how to run commands sequentially or parallel

Hi, this repo is great, serving as a good reference.

Can you add flow control tips?

  • command && command
  • command || command
  • Same things just with one & (what's the difference?)
  • command & (I think it put the result in a background process?)

Thanks

Consider adding if [ conditional expression ]

Consider adding Conditionals

Examples

if [ conditional expression1 ]
then
    #statement1
    #statement2 
else
    if [ conditional expression2 ]
    then
        #statement3 
    fi
fi
#!/bin/bash
count=99
if [ $count -eq 100 ]
then
  echo "Count is 100"
elif [ $count -gt 100 ]
then
  echo "Count is greater than 100"
else
  echo "Count is less than 100"
fi
# OR example
if [[ "$repl_IO" != "Yes" -o "$repl_SQL" != "Yes" ]] ; then

UPDATES?

Thank you for your work I appreciate been looking for a quick refresher on the key commands. And to all of those whose key commands were having issues. If a CMD'let is not working properly or to your specific requirements then altering the command individually is always an option and updating the profile with the custom cmdlets. Or you could begin to understand the light shinning behind the darkness and begin researching Darwin Series in MAC and why it was discontinued. Then maybe you can understand why things in our lives have stopped be so reliant on our personal control and we now have assistance wether we ask for it or not. ::Only after one opens their mind to the realm of possibilities;; then one can begin to open their mouth and say::: MOO!!!!!!!

Wiki - English - Ctrl + D should mention something about EOF

While it is true that Ctrl + D will exit the current shell when no process is running, it is useful to know that you can send EOF to a the running process with Ctrl + D as well.

For example:

  • cat
  • ...waiting for input
  • Ctrl + D and the process exits normally

Consider adding 'chown [options] [user] [file/folder]'

Consider adding chown

Command Description
chown [options] [user] [file/folder] Change the owner of a file
chown -f -R [user] [folder] Change the owner of a folder and files recursively

Examples

chown -f apache filename.txt
sudo chown -f -R user:group /dir

Running an app from Flash Drive

Hi,

I don't know if I'm the right place but here is what I'm trying to do.

Goal: Open an app from any mac using a flash drive.

I'm trying to run an app (QT Wallet app) from my flashdrive, this app requires to have information from it's library folder.

The app itself does not give me the option to re route the library folder thats also on the flashdrive.

Is possible to use terminal? Or perhaps use alias in this case?

Thank you!

What does ⌘Cmd + L do?

I accidentally typed ⌘Cmd + L in my Mac-Terminal and it seemed to delete the output of the previous command. I'm not sure how this shortcut is defined or where I can look it up. Does anybody have an idea?

Consider adding ;

Command Description
[command] ; [command] Separate multiple commands with ;

Examples

echo run; echo multiple; echo commands; echo from; echo one; echo line
if [ "a" == "a" ] ; then echo "true" ; fi

Sierra - Why Don't Ctrl A/E Do Anything?

I have some .bashrc & .bash_prfile commands, but none that affect bindings if that's even possible. And my Terminal preferences aren't doing anything crazy. So why won't several of these commands work for me?

Any ideas?

Consider adding apropos

Command Description
Apropos [search-pattern] Searches for command with keywords in description

I think this command is essential for finding new terminal commands. It really opens the user up to new options. It's especially useful with either -h or man [command] to look around for something that can fulfill a specific task

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.