In terminal write one of the following commands:
  • source ~/.bash_profile
  • or
  • . ~/.bash_profile
Proceed as follows
  1. Double-click Terminal. Or type terminal in spotlight and press return
  2. type sudo nano /etc/hosts in terminal then hit return. You'll be asked for your password. Enter your password
  3. Edit the hosts file as you need. I.e. enter a new line or edit a existing one
  4. Press Ctrl+O to save. You'll be asked to check the save file name, just press return
  5. Press Ctrl+X to exit nano
In terminal execute
zip -r foo.zip directory2zip -x "*.DS_Store"
In terminal execute
sudo vi ~/.bash_profile
Then add the following to ~/.bash_profile
alias lsa="ls -al"
This adds an alias named lsa to the bash session which executes the command ls -al

Show hidden files and folders

In terminal execute
defaults write com.apple.finder AppleShowAllFiles YES ; killall Finder

Hide hidden files and folders

In terminal execute
defaults write com.apple.finder AppleShowAllFiles NO ; killall Finder

Global (in /etc/paths.d)

Add new text file to /etc/paths.d (i.e. java). You can do this in terminal like this
cd /etc/paths.d
sudo vi java
Then add the location to the new text file and save it.
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin
To enable this PATH you need to reboot the system

For shell (in ~/.bash_profile)

Edit the ~/.bash_profile in your user profile (this file is hidden by default)
sudo vi ~/.bash_profile
Add the location to the ~/.bash_profile and export it
#i.e. add JAVA bin to PATH
export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

#or set JAVA_HOME variable
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

Compare two directories with DIFF

Use diff command to compare. You can do this in the terminal like this
diff -ruN orig/ new/ > file.patch
# -r == recursive, so do subdirectories
# -u == unified style, if your system lacks it or if recipient
#       may not have it, use "-c"
# -N == treat absent files as empty

Update directories with PATCH

Use patch command to update. You can do this in the terminal like this
patch -s -p0 < file.patch
# -s == silent except errors
# -p0 == needed to find the proper folder

Create public and private SSH keys

First thing that you need to do on your OSX machine is to create a directory that will store your SSH keys. Then you will generate a public and private key for your account, launch the Terminal and punch in some commands: Create a .ssh Directory Change to the home directory
cd ~/
Create a SSH directory name .ssh and move into it
mkdir .ssh ; cd .ssh
Make sure that the file permissions are set to read/write/execute only for the user
chmod go-rwx .ssh
Create your private and public key, the blank quotes at the end of the command gives the private key no password, so allowing for passwordless logins!
ssh-keygen -b 1024 -t rsa -f id_rsa -P ""

keygen-generate-ssh-keys Change into the .ssh directory and list the contents of that .ssh directory
cd .ssh ; ls -la
 -rw-------   1 username  staff   887B Jun  1 11:35 id_rsa 
 -rw-r--r--   1 username  staff   239B Jun  1 11:35 id_rsa.pub
Thats your SSH keys created, the private key is the id_rsa and the public one is the id_rsa.pub, don’t give out the private one always keep that one only on your local machine. Sharing the Public Key Create an authorized_keys in the .ssh directory of the remote computer that you want to connect to. touch authorized_keys You can create automatic logins by adding the contents of your public key to the  authorized_keys file on the remote device. To see and copy your public key use the cat command and copy the contents:
cat id_rsa.pub
ssh-rsa  AAAAB3NzaC1yc2EAAAABIwAAAIEA2CtcmYRmQJX04pZnrTPrU68BZMk9YlbI6CUcFUp
RVw29p V7mxW16wd/q9z7n+xytqdp4wsAc/7+24ZVikMhhRetEGr3LSBz5gm9980oTPEy61+pDP2y
jafShe5xcszIUnQ rN1ohCuF7Y/a/TG6G6gaJGcLexUiwfTRtCAbpuzfU= This email address is being protected from spambots. You need JavaScript enabled to view it.
On the remote computer if needed, change the permssions on the authorized_keys file to write to add the public key, on a new line paste in your public key, and change permissions back to read only after for security. Allow write on authorised_keys
chmod u+w authorized_keys
Paste the entire id_rsa.pub content with vi or nano into the authorized_keys file, if using nano use the -w flag to not use incorrect line breaks. If the remote host does not have an “authorized_keys” file simply create one and after the public key is pasted in don’t forget to takeaway write permissions.
chmod u-w authorized_keys
Going Both Ways So now when you connect via SSH no password is prompted as the remote computer has your public key which is only decrypted by your private key held in your local .ssh/ directory. If you want the communications to be bilateral then repeat the process in the opposite order between the two. Now the two computers can securely connect with no password prompting, making it ideal to script between the two for file copies or back ups. Doing it Quicker Now instead of typing in
ssh This email address is being protected from spambots. You need JavaScript enabled to view it.
Make an alias in your bash shell you could alias it to
alias now='ssh This email address is being protected from spambots. You need JavaScript enabled to view it.'
Reload the the shell
source ~/.bash_profile
Then all you have to type in is the alias
now

Enable hidden "allow app installation from unidentified sources"

Execute in CLI
sudo spctl --master-disable

Stop macOS Siera from reopening applications upon startup

Execute in CLI
defaults write -g ApplePersistence -bool no

Stop Android File Transfer from popping up

  1. Kill all Android File Transfer (AFT) processes using Activity Monitor
  2. Remove AFT from your login items
  3. Remove the agent with the following terminal command:
    rm -r ~/Library/Application\ Support/Google/Android\ File\ Transfer/Android\ File\ Transfer\ Agent.app
    
  4. Rename the agents copy with:
    cd /Applications/Android\ File\ Transfer.app/Contents/Resources 
    mv Android\ File\ Transfer\ Agent.app Android\ File\ Transfer\Agent.app.disable

See also