show hidden files

Show Hidden Library and User Library files and folder in OSX Mavericks 10.9

From OSX 10.9 Mavericks, 10.8 Mountain Lion and 10.7 Lion, the /Library and ~/Library are hidden from the Finder – to show these directories in the GUI, launch Terminal from Applications/Utilities and run the command below with sudo and enter your admin password when requested:

sudo chflags nohidden /Library/ ~/Library/
 
to hide again:

sudo chflags hidden /Library/ ~/Library/
 
You can apply this to any directories in the filing system – so to see the hidden contents of the private folder including /etc you would apply:

sudo chflags nohidden /private
 
But you cannot hide/show defined invisible files/folders that are preceded by a “.” with chflags
To show all hidden files and folders, that start with a ‘.’ , back to Terminal in OSX 10.9 Mavericks:

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder

Getting back to cleanliness:
defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder

To show all hidden files and folders, that start with a ‘.’ , back to Terminal for earlier versions of OSX 10.8 and prior:
defaults write com.apple.finder AppleShowAllFiles TRUE ; killall Finder

Getting back to cleanliness:
defaults write com.apple.finder AppleShowAllFiles FALSE ; killall Finder


Safari Tricks


Picture in Picture

When you’re watching a video, you can pop the video out from the webpage into a separate window. To do this, look in the URL box for the Audio icon. Then click and hold. A pop-up menu will appear, and one of the options is Enter Picture in Picture.

To exit Picture in Picture, you can click on the close windows icon (the X button) in the upper left corner of the video pop-up window. Or you can click and hold on the Audio icon in the URL box and select Exit Picture in Picture.

The color is controlled by the general computer settings --not in Safari;

Tabs are not very visible, Firefox is better.


iTerm2 downladed; cheat sheet

Feb 11, 2020

replaced the old version that no longer worked under Catalina

Documentation here

Cheat Sheet for iterm2:

Tabs and Windows

FunctionShortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
Splitting
Split Window Vertically (same profile) + D
Split Window Horizontally (same profile) + Shift + D (mnemonic: shift is a wide horizontal key)
Moving
Move a pane with the mouse + Alt + Shift and then drag the pane from anywhere
Fullscreen
Fullscreen+ Enter
Maximize a pane + Shift + Enter (use with fullscreen to temp fullscreen a pane!)
Resize PaneCtrl +  + Arrow (given you haven't mapped this to something else)
Less Often Used By Me
Go to Split Pane by Order of Use + ] ,  + [
Split Window Horizontally (new profile)Option +  + H
Split Window Vertically (new profile)Option +  + V
Previous Tab+ Left Arrow (I usually move by tab number)
Next Tab+ Right Arrow
Go to Window + Option + Number

Basic Moves

FunctionShortcut
Move back one characterCtrl + B
Move forward one characterCtrl + F
Delete current characterCtrl + D
Delete previous word (in shell)Ctrl + W

Moving Faster

A lot of shell shortcuts work in iterm and it's good to learn these because arrow keys, home/end keys and Mac equivalents don't always work. For example  + Left Arrow is usually the same as Home (go to beginning of current line) but that doesn't work in the shell. Home works in many apps but it takes you away from the home row.
FunctionShortcut
Move to the start of lineCtrl + A or Home
Move to the end of lineCtrl + E or End
Move forward a wordOption + F
Move backward a wordOption + B
Set Mark + M
Jump to Mark + J
Moving by word on a line (this is a shell thing but passes through fine)Ctrl + Left/Right Arrow
Cursor Jump with Mouse (shell and vim - might depend on config)Option + Left Click

Copy and Paste with iTerm without using the mouse

I don't use this feature too much.
FunctionShortcut
Enter Copy ModeShift +  + C
Enter Character Selection Mode in Copy ModeCtrl + V
Move cursor in Copy ModeHJKL vim motions or arrow keys
Copy text in Copy ModeCtrl + K
Copy actions goes into the normal system clipboard which you can paste like normal.

Search the Command History

FunctionShortcut
Search as you typeCtrl + R and type the search term; Repeat Ctrl + R to loop through result
Search the last remembered search termCtrl + R twice
End the search at current history entryCtrl + Y
Cancel the search and restore original lineCtrl + G

Misc

FunctionShortcut
Clear the screen/pane (when Ctrl + L won't work) + K (I use this all the time)
Broadcast command to all panes in window (nice when needed!) + Alt +  I (again to toggle)
Find Cursor + /  or use a theme or cursor shape that is easy to see
------------------------------

The Mac Terminal Commands Cheat Sheet

CommandAction
Shortcuts
TabAuto-complete file and folder names
Ctrl + AGo to the beginning of the line you're currently typing on
Ctrl + EGo to the end of the line you're currently typing on
Ctrl + UClear the line before the cursor
Ctrl + KClear the line after the cursor
Ctrl + WDelete the word before the cursor
Ctrl + TSwap the last two characters before the cursor
Esc + TSwap the last two words before the cursor
Ctrl + LClear the screen
Ctrl + CKill whatever you're running
Ctrl + DExit the current shell
Option + →Move cursor one word forward
Option + ←Move cursor one word backward
Ctrl + FMove cursor one character forward
Ctrl + BMove cursor one character backward
Ctrl + YPaste whatever was cut by the last command
Ctrl + ZPuts whatever you're running into a suspended background process
Ctrl + _Undo the last command
Basics
/ (Forward Slash)Top level directory
. (Single Period)Current directory
.. (Double Period)Parent directory
~ (Tilde)Home directory
sudo [command]Run command with the security privileges of the super user
nano [file]Opens the Terminal editor
open [file]Opens a file
[command] -hGet help about a command
man [command]Show the help manual of the command
Change Directory
cdHome directory
cd [folder]Change directory, e.g. cd Documents
cd ~Home directory
cd/Root of the drive
cd -Previous directory or folder you last browsed
pwdShow your working directory
cd..Move up to the parent directory
cd../..Move up two levels
List Directory Contents
lsDisplay the name of files and subdirectories in the directory
ls -CForce multi-column output of the listing
ls -aList all entries including those with .(period) and ..(double period)
ls -1Output the list of files in one entry per line format
ls -FDisplay a / (slash) immediately after each path that is a directory, * (asterisk) after executable programs or scripts, and @ after a symbolic link
ls -SSort files or entries by size
ls -lList in a long format. Includes file mode, owner and group name, date and time file was modified, pathname, and more
ls -ltList the files sorted by time modified (most recent first)
ls -lhLong listing with human readable file sizes in KB, MB, or GB
ls -loList the file names with size, owner, and flags
ls -laList detailed directory contents, including hidden files
File Size and Disk Space
duList usage for each subdirectory and its contents
du -sh [folder]Human readable output of all files in a directory
du -sDisplay an entry for each specified file
du -sk* | sort -nrList files and folders, totaling the size including the subfolders. Replace sk* with sm* to list directories in MB
df -hCalculate your system's free disk space
df -HCalculate free disk space in powers of 1,000 (as opposed to 1,024)
File and Directory Management
mkdir <dir>Create new folder named <dir>
mkdir -p <dir>/<dir>Create nested folders
mkdir <dir1> <dir2> <dir3>Create several folders at once
mkdir "<dir>"Create a folder with a space in the filename
rmdir <dir>Delete a folder (only works on empty folders)
rm -R <dir>Delete a folder and its contents
touch <file>Create a new file without any extension
cp <file> <dir>Copy a file to the folder
cp <file> <newfile>Copy a file to the current folder
cp <file>~/<dir>/<newfile>Copy a file to the folder and rename the copied file
cp -R <dir> <"new dir">Copy a folder to a new folder with spaces in the filename
cp -i <file><dir>Prompts you before copying a file with a warning overwrite message
cp <file1> <file2> <file3>/Users/<dir>Copy multiple files to a folder
rm <file>Delete a file (This deletes the file permanently; use with caution.)
rm -i <file>Delete a file only when you give confirmation
rm -f <file>Force removal without confirmation
rm <file1> <file2> <file3>Delete multiple files without any confirmation
mv <file> <newfilename>Move/rename
mv <file> <dir>Move a file to the folder, possibly by overwriting an existing file
mv -i <file> <dir>Optional -i flag to warn you before overwriting the file
mv *.png ~/<dir>Move all PNG files from current folder to a different folder
Command History
Ctrl + RSearch through previously used commands
history nShows the previous commands you've typed. Add a number to limit to the last n items
![value]Execute the last command typed that starts with a value
!!Execute the last command typed
Permissions
ls -ldDisplay the default permission for a home directory
ls -ld/<dir>Display the read, write, and access permission of a particular folder 
chmod 755 <file>Change the permission of a file to 755
chmod -R 600 <dir>Change the permission of a folder (and its contents) to 600
chown <user>:<group> <file>Change the ownership of a file to user and group. Add -R to include folder contents
Processes
ps -axOutput currently running processes. Here, a shows processes from all users and x shows processes that are not connected with the Terminal
ps -auxShows all the processes with %cpu, %mem, page in, PID, and command
topDisplay live information about currently running processes
top -ocpu -s 5Display processes sorted by CPU usage, updating every 5 seconds
top -o rsizeSort top by memory usage
kill PIDQuit process with ID <PID>. You'll see PID as a column in the Activity Monitor
ps -ax | grep <appname>Find a process by name or PID
Network
ping <host>Ping host and display status
whois <domain>Output whois info for a domain
curl -O <url/to/file>Download file via HTTP, HTTPS, or FTP
ssh <username>@<host>Establish SSH connection to <host> with user <username>
scp <file><user>@<host>:/remote/pathCopy <file> to a remote <host>
Homebrew
brew doctorCheck brew for potential problems
brew install <formula>Install a formula
brew uninstall <formula>Uninstall a formula
brew listList all the installed formulas
brew searchDisplay available formulas for brewing
brew upgradeUpgrade all outdated and unpinned brews
brew updateFetch latest version of homebrew and formula
brew cleanupRemove older version of installed formula
brew tap homebrew/caskTap the cask repository from GitHub
brew cask listList all installed casks
brew cask install <cask>Install the given cask
brew cask uninstall <cask>Uninstall the given cask
Search
find <dir> -name <"file">Find all files named <file> inside <dir>. Use wildcards (*) to search for parts of filenames
grep "<text>" <file>Output all occurrences of <text> inside <file> (add -i for case insensitivity)
grep -rl "<text>" <dir>Search for all files containing <text> inside <dir>
Output
cat <file>Output the content of <file>
less <file>Output the contents of <file> using the less command that supports pagination and more
head <file>Output the first 10 lines of <file>
<cmd> > > <file>Appends the output of <cmd> to <file>
<cmd> > <file>Direct the output of <cmd> into <file>
<cmd1> | <cmd2>Direct the output of <cmd1> to <cmd2>