Mac: Difference between revisions

From 太極
Jump to navigation Jump to search
Line 275: Line 275:
== How to Configure a Proxy Server ==
== How to Configure a Proxy Server ==
https://www.howtogeek.com/293444/how-to-configure-a-proxy-server-on-a-mac/
https://www.howtogeek.com/293444/how-to-configure-a-proxy-server-on-a-mac/
== '''watch''' command in Mac ==
http://stackoverflow.com/questions/9574089/osx-bash-watch-command
<syntaxhighlight lang='bash'>
while :; do clear; your_command; sleep 2; done
</syntaxhighlight>

Revision as of 11:08, 17 February 2017

macOS

https://en.wikipedia.org/wiki/MacOS

Darwin (operating system) and release history

Find OS version by command line

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.11.6
BuildVersion:	15G1004

$ sw_vers -productVersion
10.11.6

How to differentiate Linux and Mac

Use uname (unix name) with -s (system name) flag

# Mac
$ uname -s
Darwin

# Linux
$ uname -s
Linux

OS X File System

Home directory

/Users/USERNAME

The following is the default directories under $HOME.

$ ls ~/
Applications	Documents	Library		Music		Public	
Desktop		Downloads	Movies		Pictures

/ (root) directory

Some directory may be hidden. See http://www.westwind.com/reference/OS-X/invisibles.html

$ ls -l /
total 45
drwxrwxr-x+ 62 root  admin  2108 Feb 15 12:41 Applications
drwxr-xr-x+ 69 root  wheel  2346 Feb  9 11:02 Library
drwxr-xr-x@  3 root  wheel   102 Feb  9 08:47 Network
drwxr-xr-x@  4 root  wheel   136 Sep 16 17:07 System
drwxr-xr-x   7 root  admin   238 Feb  7 15:32 Users
drwxrwxrwt@  4 root  admin   136 Feb 15 13:32 Volumes
drwxr-xr-x@ 39 root  wheel  1326 Jul  8  2016 bin
drwxrwxr-t@  2 root  admin    68 Sep 16 16:59 cores
dr-xr-xr-x   3 root  wheel  4311 Feb  9 08:47 dev
lrwxr-xr-x@  1 root  wheel    11 Sep 16 16:59 etc -> private/etc
dr-xr-xr-x   2 root  wheel     1 Feb 14 15:31 home
-rw-r--r--@  1 root  wheel   313 Aug  2  2015 installer.failurerequests
dr-xr-xr-x   2 root  wheel     1 Feb 14 15:31 net
drwxr-xr-x@  3 root  wheel   102 Feb  9 14:58 opt
drwxr-xr-x@  6 root  wheel   204 Sep 16 16:59 private
drwxr-xr-x@ 59 root  wheel  2006 Sep 16 16:59 sbin
lrwxr-xr-x@  1 root  wheel    11 Sep 16 16:59 tmp -> private/tmp
drwxr-xr-x@ 12 root  wheel   408 Feb  9 11:02 usr
lrwxr-xr-x@  1 root  wheel    11 Sep 16 16:59 var -> private/var

/Volumes and Machintosh HD directory

Macintosh HD is just a symbolic link to / (root) on your system; that is done in /Volumes.

$ ls -l /Volumes/
total 8
lrwxr-xr-x  1 root  admin    1 Feb  9 08:47 Macintosh HD -> /
drwxrwxr-t  8 root  admin  340 Jan 18 14:06 OS X Install ESD

Terminal

Where is the terminal

Macintosh HD/Applications/Utilities/Terminal.

Keyboard shortcuts

  • Ctrl + a - going to the beginning of the line
  • Ctrl + e - going to the end of the line

More

Keyboard shortcuts (especially browser)

  • Command + up = go to the top of the document
  • Command + down = go to the end of the document
  • Command + f = search

Hardware

Display resolution

2880x1800 on my 15-Inch Retina Display MacBook Pro.

Unfortunately Virtualbox (5.1.14) can only give 1440x900 (tested on Ubuntu & Windows). See a workout http://tusharm.com/articles/win7-on-retina-display-with-virtual-box/.

Touchpad

Need to press a little bit (instead of touch) for the left-click effect.

The right click is called secondary click in OS X. By default it is click with two fingers. We can change the setting by going to System Preferences/Touchpad/Secondary click.

Scroll: two fingers move up/down. The direction is like moving a paper; i.e. scrolling up will gradually show the next part of the content.

Zoom in/out: pinch with two fingers.

Smart zoom: double-tap with two fingers.

Drag and drop: use your thumb to click on the lower part of the track and the index finger to move

CPU information

sysctl -n machdep.cpu.brand_string

My macbook Pro 2015 shows i7-4980HQ CPU @ 2.80GHz.

Finder - file manager

Keyboard

Use Command+Down instead of Enter key to open a binary file.

Use Command+Down will immediately uncompress a tar.gz file.

'Enter' key is not used to launch a program or open a file. It is used to rename a file. We can use Command + Down key to open a file.

Screenshots

Take a Timed Screenshot With the Grab (built-in) Application

http://www.howtogeek.com/278615/the-best-screenshot-apps-for-macos/

Application

How to Install Applications

Install pkg file from command line

http://apple.stackexchange.com/questions/15658/how-can-i-open-a-pkg-file-manually

sudo installer -pkg ~/Downloads/packagename.pkg -target ~/Applications/
# OR
installer -pkg ~/Downloads/packagename.pkg -target ~/Applications/

Launch an application

  • F4 key - LaunchPad
  • Command + Space - Spotlight search

Close an application

Clicking the red button does close/quit an application/a program. You need to use Command-Q.

Another answer: The red close button just closes the window. It is up to the application whether it quits or not - typically if the application uses documents or it has other windows that can be opened it will not quit. Applications with a single window (System Preferences, for example), will usually quit when the window is closed, since there isn't anything else it does.

Package

app file

Example: App Store.app, Qt application.

http://apple.stackexchange.com/questions/112197/what-does-a-app-file-actually-do

apps are "Package Bundles" is Apple jargon. These are actually Unix directories, in a special format. The actual Unix Executable File is in a subdirectory named MacOS, which you can see using the "Show Package Contents" menu in Finder.

dmg (disk image) file

Example: Google chrome, FastQC.

A DMG file is a disk image, which is sort of like an archive file. When you download one, you can double-click it to “mount” it (under Devices in the Finder), allowing you to extract the application from inside it.

After the app is dragged to your Applications folder, you can run it normally — from the Finder, Launchpad, Spotlight, dock, or anything else.

We can mount or eject a dmg file by

# mount
hdiutil mount fastqc_v0.11.5.dmg
# copy its content
mkdir -p ~/FastQC
cp -r /Volumes/FastQC/FastQC.app/Contents/MacOS/* ~/FastQC/
# eject
hdiutil eject /Volumes/FastQC/

To create a dmg file (see command line or here and GUI)

hdiutil create -volname WhatYouWantTheDiskToBeNamed \
    -srcfolder /path/to/the/folder/you/want/to/create \
    -ov -format UDZO name.dmg

To convert a dmg file to iso

hdiutil convert imagefile.dmg -format UDTO -o imagefile.iso
mv imagefile.iso.cdr imagefile.iso

pkg file

Example: R-cran

PKG files are Mac OS X installation (setup) packages that contain installer scripts ('Scripts' file) and compressed installation files ('Payload' file) that are used to install Mac software applications onto a user's hard drive.

On the case of R-x.y.z.pkg, it contains R framework, R.app GUI, Tcl/Tk X11 and TexInfo.

MacPorts, Fink and Homebrew

http://apple.stackexchange.com/questions/32724/what-are-pros-and-cons-for-macports-fink-and-homebrew

MacPorts

Homebrew

Fink

Developer

Install Xcode

http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/

xcode-select --install

The installed tools are located in /Library/Developer/CommandLineTools/usr/bin/ directory.

ldd on Mac

otool -L  <exec>

openssl

Method 1: brew

brew doctor
brew update
brew upgrade
brew install openssl
cd /usr/local/include
ln -s ../opt/openssl/include/openssl .

Method 2: compile yourself

VirtualBox

Note the official image (e.g. Install macOS Sierra.app) we downloaded from Apple Store is saved under /Applications folder.

https://github.com/geerlingguy/macos-virtualbox-vm

Unfortunately, the Mac guest machine cannot install guest additions.

Remote connection (ssh)

Use Preferences -> Sharing -> Select Remote Login. http://osxdaily.com/2011/09/30/remote-login-ssh-server-mac-os-x/

To uses a command line to enable it, see

Tips

Got a New Mac? Do This First!

http://www.makeuseof.com/tag/new-mac-setup/

Upgrading to macOS Sierra (nee OSX) for R users

http://www.win-vector.com/blog/2017/01/upgrading-to-macos-sierra-nee-osx-for-r-users/

Access the Root Directory

http://osxdaily.com/2013/01/17/access-root-directory-mac-os-x/

Disable update notification

http://news.softpedia.com/news/how-to-disable-os-x-update-notifications-493961.shtml

How to Configure a Proxy Server

https://www.howtogeek.com/293444/how-to-configure-a-proxy-server-on-a-mac/

watch command in Mac

http://stackoverflow.com/questions/9574089/osx-bash-watch-command

while :; do clear; your_command; sleep 2; done