Key icon

iconkey
command
option
shift
caps lock
control
return
enter
home
end
pagedown
pageup
esc

Brew

brew 又叫 Homebrew,是 Mac OSX上的软件包管理工具。类似 ubuntu 中的 apt-get

  • Install
$   /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如下

houbinbindeMacBook-Pro:tools houbinbin$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
/usr/local/etc
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their owner set to houbinbin:
/usr/local/bin
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their group set to admin:
/usr/local/bin
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/etc
/usr/local/opt
/usr/local/sbin
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin /usr/local/etc /usr/local/lib /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin /usr/local/etc /usr/local/lib /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> /usr/bin/sudo /usr/sbin/chown houbinbin /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/opt /usr/local/sbin /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
mkdir: /usr/local/etc: Not a directory
Failed during: /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/opt /usr/local/sbin /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var

1、 遇到这个报错

mkdir: /usr/local/etc: Not a directory

不知道原来为何有一个 etc 文件。估计是 redis 相关的。复制成了其他名称然后删除了。重新跑。

2、 第二个问题

/usr/local/Homebrew/.git: Permission denied
Failed during: git init -q

我的解决方式, 删除2个文件夹

sudo rm -rf /usr/local/Cellar
sudo rm -rf /usr/local/Homebrew

重新运行

houbinbindeMacBook-Pro:local houbinbin$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown houbinbin /usr/local/Cellar /usr/local/Homebrew
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 5292, done.
remote: Compressing objects: 100% (3328/3328), done.
remote: Total 5292 (delta 2877), reused 3505 (delta 1791), pack-reused 0
Receiving objects: 100% (5292/5292), 2.78 MiB | 82.00 KiB/s, done.
Resolving deltas: 100% (2877/2877), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
 * ...
HEAD is now at fa34aa2 Merge pull request #2232 from reitermarkus/spec-mktmpdir
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4165, done.
remote: Compressing objects: 100% (4018/4018), done.
remote: Total 4165 (delta 32), reused 434 (delta 10), pack-reused 0
Receiving objects: 100% (4165/4165), 3.31 MiB | 62.00 KiB/s, done.
Resolving deltas: 100% (32/32), done.
Checking connectivity... done.
Tapped 4016 formulae (4,196 files, 10.4M)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/houbinbin/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
Error: Failed to link all completions, docs and manpages:
  Permission denied - (../../../Homebrew/completions/zsh/_brew, /usr/local/share/zsh/site-functions/_brew)
Failed during: /usr/local/bin/brew update --force

没有错,又报错了。。。心累。因为此时的 brew 命令已经是有效的了,我想直接卸载再重装。或者先用着再说。

  • Un-install
$   /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

删除后重新安装。OKay

  • Usage
houbinbindeMacBook-Pro:local houbinbin$ brew install tree
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/tree-1.7.0.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
==> Trying a full download
######################################################################## 100.0%
==> Pouring tree-1.7.0.el_capitan.bottle.1.tar.gz
🍺  /usr/local/Cellar/tree/1.7.0: 7 files, 113.3K

使用 tree --help 可查看 此命令使用方式。

Command

一、File tree

zh_CN

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

install tree

二、Get ip

$   ifconfig

port

  • find port
sudo lsof -i :8080

COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    15072 houbinbin   48u  IPv6 0xf1b9bfa3c85fd519      0t0  TCP *:http-alt (LISTEN)
  • kill thread
sudo kill -9 15072

.bash_profile

文件修改错误,导致命令无法使用。

export PATH=/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

然后修改回来

source ~/.bash_profile

make it work at once.

  • add new bin
M3_HOME=/usr/local/maven/maven3.3.9
ARC_HOME=/Users/houbinbin/it/code/arcanist

PATH=$ARC_HOME/bin:$M3_HOME/bin:$PATH

zip & unzip

zip

最通俗的用法

zip -q -r -e -m -o myfile.zip someThing

-q 表示不显示压缩进度状态

-r 表示子目录子文件全部压缩为zip //这部比较重要,不然的话只有something这个文件夹被压缩,里面的没有被压缩进去

-e 表示你的压缩文件需要加密,终端会提示你输入密码的

// 还有种加密方法,这种是直接在命令行里做的,比如zip -r -P Password01! modudu.zip SomeDir, 就直接用Password01!来加密modudu.zip了。

-m 表示压缩完删除原文件

-o 表示设置所有被压缩文件的最后修改时间为当前压缩时间

当跨目录的时候是这么操作的

zip -q -r -e -m -o ‘\user\someone\someDir\someFile.zip’ ‘\users\someDir’

unzip

unzip [选项] 压缩文件名.zip

各选项的含义分别为:

-x 文件列表 解压缩文件,但不包括指定的file文件。

-v 查看压缩文件目录,但不解压。

-t 测试文件有无损坏,但不解压。

-d 目录 把压缩文件解到指定目录下。

-z 只显示压缩文件的注解。

-n 不覆盖已经存在的文件。

-o 覆盖已存在的文件且不要求用户确认。

-j 不重建文档的目录结构,把所有文件解压到同一目录下。

Mac 制作 ubuntu 启动U盘

blog zh_CN

blog2 zh_CN

JDK 配置

一般而言,是不用关心JDK配置的。可是有时需要使用ROOT权限时,如果涉及到JDK。可能会找不到。

前提先提升权限

su
  • 获取JDK位置
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
  • 全局配置JDK

vi /etc/profile

添加内容如下:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH
  • 使其立即生效
source /etc/profile
  • test
# echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

端口占用

命令 lsof -i tcp:port (port替换成端口号,比如6379)可以查看该端口被什么程序占用,并显示PID,方便KILL

目录直达

CMD+SHIF+G

or

命令行打开指定路径,然后 open .