Skip to content

Instantly share code, notes, and snippets.

@RickJP
Created November 24, 2019 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickJP/862aaf7c8d4bc03f73d71cfa21b4bca6 to your computer and use it in GitHub Desktop.
Save RickJP/862aaf7c8d4bc03f73d71cfa21b4bca6 to your computer and use it in GitHub Desktop.
CORE => LINUX - MASTER THE COMMANDS
CORE => LINUX TERMINAL, MAC
MASTER THE COMMANDS
TERMINAL SHORCUTS CHEATSHEET
https://github.com/0nn0/terminal-mac-cheatsheet
KILL PROCESS
killall appname
kill PID
COPY ALL TEXT OF A MAN PAGE
man ssh | col -b | pbcopy
MAKE COPY MAN PAGE AN ALIAS
alias mancp='man -P "col -b | pbcopy"'
READ A MAN PAGE IN PREVIEW OR FOR THE TEXTEDIT VERSION
man -t ssh | open -f -a Preview man ssh | col -b | open -f -e
PREVIEWING A FILE
qlmanage -p myimage.png >& /dev/null
VIEW MULTIPLE IMAGES AT ONCE
qlmanage -p *.png >& /dev/null
CHANGE PASSWORD
passwd <USERNAME>
LIST ALL FILES THAT START WITH ‘f’ AND COPY THEM TO CLIPBOARD
ls f* | pbcopy
COPY FROM CLIPBOARD ALL LINES CONTAINING THE CHAR ‘foo’
pbpaste | grep foo
COPIES ANY FILES IN SOURCE BUT NOT DESTINATION (DOES NOT DELETE FILES)
rsync -av /path/to/directory1/ /path/to/directory/2/
MIRROR FILES IN SOURCE DIR TO DESTINATION (MAY DELETE FILES)
rsync -av --delete /path/to/directory1/ /path/to/directory2/
“”(BUT DON’T LIST THE FILES)
rsync -a --delete /path/to/directory1/ /path/to/directory2/
(YOU WANT TO SEEWHICH FILES WILL BE COPIED)
rsync -avn --delete /path/to/directory1/ /path/to/directory2/
(CAN USE WITH REMOTE AS LONG AS RSYNC IS INSTALLED AND RUNNING SSH)
rsync -av --delete /path/to/directory1/ user@remotesystem:/path/to/directory1/
COPY / MERGE DIRECTORIES
ditto /path/to/source /path/to/destination
BACKUP & RESTORE WITH TIME MACHINE
tmutil listbackups
tmutil latestbackup
DISPLAY FILE SYSTEM ACTIVITY
sudo fs_usage
(IF YOU’RE USING ANOTHER TERMINAL, YOU NEED TO EXEMPT IT FROM THE OUTPUT)
sudo fs_usage -e iTerm
VIEW INDIVIDUAL PROCESS INFO
sudo fs_usage "Google Chrome"
VIEW HIDDEN FILES & FOLDERS
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
killall Finder
REPORT SYSTEM INFORMATION
system_profiler
cd ~/Downloads/
curl -O [the URL of the file]
CHECK UPDATES MORE OFTEN
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
CHANGE DEFAULT SCREENSHOT LOCATION
defaults write com.apple.screencapture location ~/your/location/here
killall SystemUIServer
CREATE A NEW DEFAULT NAME FOR SCREENSHOTS
defaults write com.apple.screencapture name "New Screen Shot Name"
killall SystemUIServer
CHANGE WHAT FORMAT YOU MAKE YOUR SCREENSHOTS
defaults write com.apple.screencapture type jpg
DISABLE THE DASHBOARD
defaults write com.apple.dashboard mcx-disabled -boolean TRUE
killall Dock
ADD A GAP BETWEEN APPS IN THE DOCK
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'
killall Dock
VIEW ENTIRE DL HISTORY
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
DELETE ENTIRE DL HISTORY
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
PUT COMPUTER TO SLEEP OR RESTART
sudo shutdown -h now
sudo shutdown -r now
GIVE ALL PERMISSIONS ON FOLDER
chmod u+rx,go-w <FOLDER>
========================================================================================================================================================================================
I have the complete shortcuts list:
1. Ctrl+a Move cursor to start of line
2. Ctrl+e Move cursor to end of line
3. Ctrl+b Move back one character
4. Alt+b Move back one word
5. Ctrl+f Move forward one character
6. Alt+f Move forward one word
7. Ctrl+d Delete current character
8. Ctrl+w Cut the last word
9. Ctrl+k Cut everything after the cursor
10. Alt+d Cut word after the cursor
11. Alt+w Cut word before the cursor
12. Ctrl+y Paste the last deleted command
13. Ctrl+_ Undo
14. Ctrl+u Cut everything before the cursor
15. Ctrl+xx Toggle between first and current position
16. Ctrl+l Clear the terminal
17. Ctrl+c Cancel the command
18. Ctrl+r Search command in history - type the search term
19. Ctrl+j End the search at current history entry
20. Ctrl+g Cancel the search and restore original line
21. Ctrl+n Next command from the History
22. Ctrl+p previous command from the History
*
macOS Terminal cheat sheet
By Markus Wein • 369 Words
The Terminal on macOS offers quite an amount of functionality, but most of it is hard to discover unless you already know what you’re looking for. So here’s a quick cheat sheet explaining unique functions with their corresponding key combos:
Marks
Marks allow you to mark certain lines in the output, and allow you to jump between different parts of the output.
By default, every time you hit enter on your prompt, Terminal will automatically insert a mark for you. You can configure this in the Edit menu, under Marks with the option Automatically Mark Prompt Lines.
Marks are visualised in the Terminal window as light grey square brackets (They are not, however, part of the output).
* Cmd-⬆: Jump to previous mark
* Cmd-⬇: Jump to next mark
* Cmd-Shift-A: Selects the output between the current marks
* Cmd-Enter: Enter, and will always create a mark
* Cmd-Shift-Enter: Enter, but will never create a mark
* Cmd-U: Create mark
* Cmd-Shift-U: Remove mark
* Cmd-L: Clear screen to previous mark
Bookmarks
Similar to marks, they can optionally be named, and are more useful to denote larger sections of the output. They are denoted by light grey bars.
* Cmd-Shift-M: Insert Bookmark
* Cmd-Option-U: Mark current line as bookmark
* Cmd-Shift-Option-M: Insert named bookmark
* Cmd-Option-⬆: Jump to previous bookmark
* Cmd-Option-⬇: Jump to next bookmark
* Cmd-Option-L: Clear to previous bookmark
Panes
View different parts of the scrollback buffer of the same terminal.
* Cmd-D: Split window into panes
* Cmd-Shift-D: close split pane
Miscellaneous
* Cmd-K: Clear everything
* Cmd-Option-K: Clear scroll back (everything except what you see on the screen)
* Cmd-Option-O: Toggle use of option as meta key
* Cmd-Ctrl-V: Paste escaped text. Useful for pasting e.g. paths containing whitespace.
* Cmd-Shift-Option-C: Copy as plain text
* Cmd-Option-PageUp or PageDown: Scroll one line up/down
* Cmd-[ or ]: Switch between windows
* Cmd-Shift-[ or ]: Switch between tabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment