为mac终端添加tree命令

原文:http://superuser.com/questions/359723/mac-os-x-equivalent-of-the-ubuntu-tree-command/

整理步骤如下:

$ tree
-bash: tree: command not found
$ sudo mkdir -p /usr/local/bin
Password:
$ sudo nano /usr/local/bin/tree

------------复制下面到nano编辑器中-------------
#!/bin/bash

SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g'

if [ "$#" -gt 0 ] ; then
   dirlist="$@"
else
   dirlist="."
fi

for x in $dirlist; do
     find "$x" -print | sed -e "$SEDMAGIC"
done
------------复制上面到nano编辑器中-------------

$ sudo chmod 755 /usr/local/bin/tree
$ nano ~/.bash_profile

------------复制下面到nano编辑器中-------------
export PATH="/usr/local/bin:$PATH"
------------复制上面到nano编辑器中-------------

$ tree ~/Desktop/
| | | |____
| | | | |____.DS_Store
| | | | |____.localized
| | | | |____readme.txt
$
原文地址:https://www.cnblogs.com/Bob-wei/p/4633755.html