πŸ“ Repo Link

🐭 Bye Bye Mouse

Because real power users don't double-clickβ€”they type :)

Escape the tyranny of the GUI one command at a time! This repo is your golden ticket to slick shell tricks, terminal wizardry, and keyboard-fueled productivity. Unplug that mouse and watch your workflow sprint.

copy a file

STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + C, CMD/CTRL + V A FILE πŸ‘Ž

Copy readme.txt to the documents directory

$ cp readme.txt documents/
Go to table of contents πŸ”Ό

duplicate a file

STOP RIGHT CLICKING AND DUPLICATE A FILE πŸ‘Ž
$ cp readme.txt readme.bak.txt

More advanced:

$ cp readme{,.bak}.txt
# Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.
Go to table of contents πŸ”Ό

copy a directory

STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + C, CMD/CTRL + V A DIRECTORY πŸ‘Ž

Copy myMusic directory to the myMedia directory

$ cp -a myMusic myMedia/
# or
$ cp -a myMusic/ myMedia/myMusic/
Go to table of contents πŸ”Ό

duplicate a directory

STOP RIGHT CLICKING AND DUPLICATE A DIRECTORY πŸ‘Ž
$ cp -a myMusic/ myMedia/
# or if `myMedia` folder doesn't exist
$ cp -a myMusic myMedia/
Go to table of contents πŸ”Ό

move a file

STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE πŸ‘Ž
$ mv readme.txt documents/

Always use a trailing slash when moving files, for this reason.

Go to table of contents πŸ”Ό

rename a file

STOP RIGHT CLICKING AND RENAME A FILE πŸ‘Ž
$ mv readme.txt README.md
Go to table of contents πŸ”Ό

move a directory

STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + X, CMD/CTRL + V A DIRECTORY πŸ‘Ž
$ mv myMedia myMusic/
# or
$ mv myMedia/ myMusic/myMedia
Go to table of contents πŸ”Ό

rename a directory

STOP RIGHT CLICKING AND RENAME A DIRECTORY πŸ‘Ž
$ mv myMedia/ myMusic/
Go to table of contents πŸ”Ό

merge directories

STOP DRAG AND DROPPING TO MERGE DIRECTORIES πŸ‘Ž
$ rsync -a /images/ /images2/	# note: may over-write files with the same name, so be careful!
Go to table of contents πŸ”Ό

create a new file

STOP RIGHT CLICKING AND CREATE A NEW FILE πŸ‘Ž
$ touch 'new file'    # updates the file's access and modification timestamp if it already exists
# or
$ > 'new file'        # note: erases the content if it already exists
Go to table of contents πŸ”Ό

create a new directory

STOP RIGHT CLICKING AND CREATE A NEW DIRECTORY πŸ‘Ž
$ mkdir 'untitled folder'
# or
$ mkdir -p 'path/may/not/exist/untitled folder'
Go to table of contents πŸ”Ό

show file/directory size

STOP RIGHT CLICKING AND SHOW FILE/directory INFO πŸ‘Ž
$ du -sh node_modules/
Go to table of contents πŸ”Ό

show file/directory info

STOP RIGHT CLICKING AND SHOW FILE/DIRECTORY INFO πŸ‘Ž
$ stat -x readme.md   # on macOS
$ stat readme.md      # on Linux
Go to table of contents πŸ”Ό

open a file with the default program

STOP DOUBLE CLICKING ON A FILE πŸ‘Ž
$ xdg-open file   # on Linux
$ open file       # on MacOS
$ start file      # on Windows
Go to table of contents πŸ”Ό

open a file in any application

STOP RIGHT CLICKING AND OPEN WITH πŸ‘Ž
$ open -a appName file
Go to table of contents πŸ”Ό

zip a directory

STOP RIGHT CLICKING AND COMPRESS DIRECTORY πŸ‘Ž
$ zip -r archive_name.zip folder_to_compress
Go to table of contents πŸ”Ό

unzip a directory

STOP RIGHT CLICKING AND UNCOMPRESS DIRECTORY πŸ‘Ž
$ unzip archive_name.zip
Go to table of contents πŸ”Ό

peek files in a zip file

STOP USING WinRAR πŸ‘Ž
$ zipinfo archive_name.zip
# or
$ unzip -l archive_name.zip
Go to table of contents πŸ”Ό

remove a file

STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY πŸ‘Ž
$ rm my_useless_file

IMPORTANT: The rm command deletes my_useless_file permanently, which is equivalent to move my_useless_file to Recycle Bin and hit Empty Recycle Bin.

Go to table of contents πŸ”Ό

remove a directory

STOP RIGHT CLICKING AND DELETE A DIRECTORY PERMANENTLY πŸ‘Ž
$ rm -r my_useless_folder
Go to table of contents πŸ”Ό

remove all files of certain criteria

$ find . -name "*.bak" -type f -delete

IMPORTANT: run find . -name "*.bak" -type f first to see exactly which files you will remove.

Go to table of contents πŸ”Ό

list directory contents

STOP OPENING YOUR FINDER OR FILE EXPLORER πŸ‘Ž
$ ls my_folder        # Simple
$ ls -la my_folder    # -l: show in list format. -a: show all files, including hidden. -la combines those options.
$ ls -ltrha my_folder # -r: reverse output. -t: sort by time (modified). -h: output human-readable sizes.
Go to table of contents πŸ”Ό

tree view a directory and its subdirectories

STOP OPENING YOUR FINDER OR FILE EXPLORER πŸ‘Ž
$ tree                                                        # on Linux
$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'      # on MacOS
# Note: install homebrew (https://brew.sh) to be able to use (some) Linux utilities such as tree.
# brew install tree
Go to table of contents πŸ”Ό

find a stale file

STOP USING YOUR FILE EXPLORER TO FIND A FILE πŸ‘Ž

Find all files modified more than 5 days ago

$ find my_folder -mtime +5
Go to table of contents πŸ”Ό

show a calendar

STOP LOOKING UP WHAT THIS MONTH LOOKS LIKE BY CALENDAR WIDGETS πŸ‘Ž

Display a text calendar

$ cal

Display selected month and year calendar

$ cal 11 2018
Go to table of contents πŸ”Ό

find a future date

STOP USING WEBAPPS TO CALCULATE FUTURE DATES πŸ‘Ž

What is today's date?

$ date +%m/%d/%Y

What about a week from now?

$ date -d "+7 days"                                           # on Linux
$ date -j -v+7d                                               # on MacOS
Go to table of contents πŸ”Ό

use a calculator

STOP USING CALCULATOR WIDGET πŸ‘Ž
$ bc -l
Go to table of contents πŸ”Ό

force quit a program

STOP CTRL + ALT + DELETE and choose the program to kill πŸ‘Ž
$ killall -9 program_name
Go to table of contents πŸ”Ό

check server response

STOP OPENING A BROWSER πŸ‘Ž
$ curl -i rbtreevi.web.app
# curl's -i (--include) option includes HTTP response headers in its output.
Go to table of contents πŸ”Ό

view content of a file

STOP DOUBLE CLICKING A FILE πŸ‘Ž
$ cat apps/settings.py
# if the file is too big to fit on one page, you can use a 'pager' (less) which shows you one page at a time.
$ less apps/settings.py
Go to table of contents πŸ”Ό

search for a text in a file

STOP CMD/CTRL + F IN A FILE πŸ‘Ž
$ grep -i "Query" file.txt
Go to table of contents πŸ”Ό

search in all files in current working directory, quickly (entire disk in less than 15 minutes)

STOP CMD/CTRL + F IN A DIRECTORY πŸ‘Ž
$ ripgrep -i "Query"
# brew install ripgrep
Go to table of contents πŸ”Ό

view an image

STOP USING PREVIEW πŸ‘Ž
$ imgcat image.png
# Note: requires iTerm2 terminal.
Go to table of contents πŸ”Ό

show disk size

STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY πŸ‘Ž
$ df -h
Go to table of contents πŸ”Ό

check cpu usage, processes and RAM

STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER πŸ‘Ž
$ top

if you want some more details:

$ htop
Go to table of contents πŸ”Ό

know whether your computer is under load, and whether it's due to memory or CPU

$ glances
# brew install glances
# pip install --user 'glances[all]'
Go to table of contents πŸ”Ό

poweroff or reboot your computer

This can be useful when you're patching a server that is accessed via SSH and you don't have a GUI.

# poweroff
$ sudo shutdown -h now
# reboot
$ sudo shutdown -r now
Go to table of contents πŸ”Ό

locate USB drives

$ df
Go to table of contents πŸ”Ό

unmount USB drives

$ sudo umount /dev/sdb1
Go to table of contents πŸ”Ό

format USB drives

# FAT32
$ sudo mkfs.vfat /dev/sdb1
# NTFS
$ sudo mkfs.ntfs /dev/sdb1
# exFAT
$ sudo mkfs.exfat /dev/sdb1
Go to table of contents πŸ”Ό

check USB format

$ sudo fsck /dev/sdb1
Go to table of contents πŸ”Ό

run command on all files of a directory

STOP CLICKING THE FILES ONE BY ONE πŸ‘Ž
$ for FILE in *; do echo $FILE; done
Go to table of contents πŸ”Ό

check network connectivity to a remote address and port

STOP USING NETWORK UTILITY
$ nc -vz www.google.com 443
$ nc -vz 1.1.1.1 53
Go to table of contents πŸ”Ό

check DNS config of a domain

STOP USING NETWORK UTILITY
$ dig www.google.com
Go to table of contents πŸ”Ό

check the ownership and registration of a domain

STOP USING NETWORK UTILITY AND THE WEBSITE OF DOMAIN REGISTRATION PROVIDERS
$ whois www.google.com
Go to table of contents πŸ”Ό

Hotkeys

Hotkey Description
Ctrl+AGo to the beginning of the line you are currently typing on
Ctrl+EGo to the end of the line you are currently typing on
Ctrl+LClears the Screen, similar to the clear command
Ctrl+UClears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl+HSame as backspace
Ctrl+RLets you search through previously used commands
Ctrl+CKill whatever you are running
Ctrl+DExit the current shell
Ctrl+ZPuts whatever you are running into a suspended background process. fg restores it.
Ctrl+WDelete the word before the cursor
Ctrl+KClear the line after the cursor
Ctrl+TSwap the last two characters before the cursor
Ctrl+FMove cursor forward one character
Ctrl+BMove cursor backward one character
Esc+TSwap the last two words before the cursor
Alt+TSame as Esc + T
Alt+FMove cursor forward one word on the current line
Alt+BMove cursor backward one word on the current line
Esc+FSame as Alt + F
Esc+BSame as Alt + B
Alt+.Paste the last word of the most recently command
TabAuto-complete files and directory names
Go to table of contents πŸ”Ό

I can't remember these cryptic commands

You can always google or man the commands you are not familiar with. Or, checkout tldr, a collection of simplified and community-driven man pages.

Go to table of contents πŸ”Ό
MacOS Theme