顯示具有 mac 標籤的文章。 顯示所有文章
顯示具有 mac 標籤的文章。 顯示所有文章

2017/7/9

clang簡介

昨天在練習c語言的時候,無聊的想查一下電腦的gcc版本是什麼,
使用的是 gcc --version 這個指令。
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
一查才知道原來電腦裡裝的是另一個代替gcc的編譯器---clang

[ 關於clang ]
是一個C、C++、Objective-C和Objective-C++程式語言的編譯器前端。它採用了底層虛擬機(LLVM)作為其後端。它的目標是提供一個GNU編譯器套裝(GCC)的替代品。作者是克里斯·拉特納,在蘋果公司的贊助支援下進行開發,而原始碼授權是使用類BSD的伊利諾伊大學厄巴納-香檳分校開源碼許可。
Clang專案包括Clang前端和Clang靜態分析器等。

這個軟體專案在2005年由蘋果電腦發起,是LLVM編譯器工具集的前端(front-end),目的是輸出代碼對應的抽象語法樹(Abstract Syntax Tree, AST),並將程式碼編譯成LLVM Bitcode。接著在後端(back-end)使用LLVM編譯成平台相關的機器語言 。Clang支援C、C++、Objective C。
在Clang語言中,使用Stmt來代表statement。Clang程式碼的單元(unit)皆為語句(statement),語法樹的節點(node)類型就是Stmt。另外Clang的運算式(Expression)也是語句的一種,Clang使用Expr來代表Expression,Expr本身繼承自Stmt。節點之下有子節點列表(sub-node-list)。
Clang本身效能優異,其生成的AST所耗用掉的記憶體僅僅是GCC的20%左右。FreeBSD 10將Clang/LLVM作為預設編譯器。

[ 效能 ]
測試證明Clang編譯Objective-C代碼時速度為GCC的3倍,還能針對使用者發生的編譯錯誤準確地給出建議


來源 : wikipedia

-----------------------
註:
在stackexchange上面查到可以找出電腦gcc的指令(但不知是取自哪)
gcc -dumpversion | cut -f1,2,3 -d. 


我的是4.2.1 (改-fl後面的1,2,3可選擇顯示版本小數點數 如 -fl1 輸出為4)

2017/6/4

安裝binary檔案到osx/linux並使用其terminal指令

有時候我們在網路上找到的程式是binary檔而不是osx上常見的dmg,這時候就要將其移動到系統當中的一個特定地點 /usr/local/bin,osx/linux只會從這些資料夾查看可以使用的程式。

安裝方法:
將下載來的binary檔案移動到 /usr/local/bin 即可在terminal中使用其指令。

可以使用 mv 或者 cp 這兩個指令
用法:
mv [source] [destination]
cp [source] [destination]


說明:
When you type commands like ngrok in the terminal, Macs (and other Unix OSs) look for these programs in the folders specified in your PATH. The PATH is a list of folders that's specified by each user. To check your path, open the terminal and type: echo $PATH.
You'll see output that looks something like: /usr/local/bin:/usr/bin:/bin. This is a : separated list of folders.
So when you type ngrok in the terminal, your Mac will look for this executable in the following folders: /usr/local/bin, /usr/bin/ and /bin.


像我目前如果在terminal中輸入 echo $PATH 則會出現:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin
代表這些地方都有存放可在terminal中執行指令的程式


各個path的比較:

  1. /bin (and /sbin) were intended for programs that needed to be on a small / partition before the larger /usr, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh, although the original intent may still be relevant for e.g. installations on small embedded devices.
  2. /sbin, as distinct from /bin, is for system management programs (not normally used by ordinary users) needed before /usr is mounted.
  3. /usr/bin is for distribution-managed normal user programs.
  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin.
  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.
  6. /usr/local/sbin, as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin.

      In addition, there is also /opt which is for monolithic non-distribution packages, although before they were properly integrated various distributions put Gnome and KDE there. Generally you should reserve it for large, poorly behaved third party packages such as Oracle.





參考資料:
https://stackoverflow.com/questions/30188582/ngrok-command-not-found
https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux 
https://linux.die.net/man/7/hier

2017/4/29

安全的關閉你的RPI

這裡的RPI為Raspberry Pi 的簡稱。

-

對於一個製造精細的機器來說,如果在他內部有程式仍在運行就強行將電源關閉是一件有風險的事情,因為這麼做可能會導致硬碟內部檔案系統毀損,造成檔案的遺失,所以我們在每次使用完畢要關機時都必須確保所有的程式都停止運作了。

如何安全地關閉你的raspberry pi呢?

只要打開終端機,輸入以下指令即可。
sudo shutdown -h now




參考資料:
http://raspi.tv/2012/how-to-safely-shutdown-or-reboot-your-raspberry-pi

2017/3/18

mac的System Integrity Protection

自從EL Capitan之後,mac增加了系統完整性保護的機制,
如果要在自己的電腦上灌多系統的話,用refi可能會遇到這個問題。


------------------------------------------------------------------------------------------------------------------------------
關閉的方法:
重開你的電腦,在進去開機畫面前按住Cmd + R,
接著進入Terminal


輸入:
“csrutil disable”






-----------------------------------------------------------------------------------------------------------------------------

重啟的方法:
"csrutil enable"




2017/3/14

RPI - 從燒錄映像檔到遠端ssh連線

首先,準備一張sd卡和sd卡轉接頭,
把sd卡連接到你的筆電上,
df -h查詢目前硬碟的狀態(diskutil list也可以)
 










可以發現我的SD卡的位置在/etc/disk3s1,記住"3"這個數字





接著unmount(取消掛載)掉




進入你放置映像檔的資料夾,輸入 dd 指令燒錄映像檔,




完成後退出SD卡
成功燒錄~

---------------------------------------------------------------------

後來要從筆電ssh至pi 3時發現ssh功能在2016年11月後出廠的板子是預設unenable的,
據官網說明必須先把一個檔案名為ssh的文件放入sd卡才能開啟此功能







恩...
接著用網路線連接你的router跟樹莓派,開啟DHCP伺服器,
樹莓派就可以拿到一組router分配的ip囉(這次是192.168.0.107)
開始用ssh連上你的樹莓派吧!




 
使用raspi-config可以做一些基本設定


--------------------------------------------------------------------------------------
[手邊沒螢幕? 試試遠端模擬桌面吧]

首先要先在樹莓派安裝VNCServer,sudo apt-get install tightvncserver
在樹莓派上執行vncserver,就可開啟伺服器,電腦端就可以透過遠端模擬桌面囉




可以使用vncviewer這款軟體來在你電腦開啟遠端桌面的圖形化介面,
或者mac的使用者可以在finder內按cmd+k (連接伺服器),輸入vnc://[ip] ,同樣可以連上。

2017/3/13

df指令(檢查linux的檔案系統的磁碟空間佔用情況)



df [選項] [檔]



功能:

顯示指定磁片檔的可用空間。如果沒有檔案名被指定,則所有當前被掛載的檔案系統的可用空間將被顯示。預設情況下,磁碟空間將以 1KB 為單位進行顯示,除非環境變數 POSIXLY_CORRECT 被指定,那樣將以512位元組為單位進行顯示



<命令參數>
必要參數:

-a 全部檔案系統清單


-h 方便閱讀方式顯示


-H 等於“-h”,但是計算式,1K=1000,而不是1K=1024


-i 顯示inode資訊


-k 區塊為1024位元組


-l 只顯示本地檔案系統


-m 區塊為1048576位元組


--no-sync 忽略 sync 命令


-P 輸出格式為POSIX


--sync 在取得磁片資訊前,先執行sync命令


-T 檔案系統類型


選擇參數:

--block-size=<區塊大小> 指定區塊大小

-t<檔案系統類型> 只顯示選定檔案系統的磁片資訊

-x<檔案系統類型> 不顯示選定檔案系統的磁片資訊

--help 顯示説明資訊

--version 顯示版本資訊











----------------------------------------


參考資料:
http://jashliao.pixnet.net/blog/post/162893228-%E6%AF%8F%E5%A4%A9%E4%B8%80%E5%80%8Blinux%E6%8C%87%E4%BB%A4--df%E6%8C%87%E4%BB%A4(%E6%AA%A2%E6%9F%A5linux%E4%BC%BA%E6%9C%8D%E5%99%A8%E7%9A%84%E6%AA%94


http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html

2017/3/3

mac terminal常用指令

  • clear: 清除屏幕。
  • pwd: 查看目前路徑。
  • cd: 進入目錄,常常配合一些字符使用。比如:
    • ..: 返回上層目錄。
    • ~: 返回使用者主目錄。
    • -: 返回上次操作目錄。
    • /: 返回系统根目錄。
  • ls: 列出目錄信息。
  • mkdir: 新增目錄(資料夾)。
  • touch: 創建檔案。
  • cp: 拷貝文件。
  • mv: 移動文件,或者重命名文件。
  • rm:删除文件。
  • cat: 查看文件内容。
  • grep: 查找文本信息。
  • man: 手册命名,查看各個命名的幫助。
  • open:開啟檔案/目錄/程式    open . : 開啟finder

2017/2/24

vim 基本指令

今天終於來學vim囉~
來分享一下今天學到的東西吧!




-
esc : command mode
i : text editor mode

< command mode中的游標控制 >
hjkl : 上下左右
^ : 到同一列最前面
$ : 到同一列最後面
G : 到最後一列第一個字
gg : 到第一列第一個字
dd : 刪掉一列(有cut的功能)
dw : 刪掉一個單字
u : 回復(undo)
y : 拷貝(yank)
yw : 拷貝一個單字
yy : 拷貝一列
p : 貼上


進階技巧 - 組合鍵:
數字+h/j/k/l : 可任意移動游標
d + ^ / d + $ : 從目前的地方刪到最前面/最後面
2yy : 拷貝二列
y + $ : 從目前的地方複製到最後面

...以此類推。




2017/2/11

我的sublime text 3自訂設定

本文將會陸續更新。

-----------------------------
[2017.02.11]
color scheme by daylerees
https://github.com/daylerees/colour-schemes


------------------------------

[2017.05.10]
package manager
已安裝的套件:


















-----------------------------
[2017.06.17]
新增套件:
SideBarEnhancements
https://packagecontrol.io/packages/SideBarEnhancements

Seti_UI
https://packagecontrol.io/packages/Seti_UI


參考:
https://code.kpman.cc/2014/10/14/sublime-text-3-mac-%E6%8C%87%E5%8D%97/

2017/1/26

控制顯示 Mac 中的隱藏檔案

要如何控制要不要開啟Mac 中的Finder 裡面隱藏的檔案要不要被我們看到呢?
非常簡單,只要幾個按鍵就可達成囉~




-------------------------------------------------------------------------


開啟Terminal,直接輸入以下指令(二擇一)即可


顯示隱藏的檔案
defaults write com.apple.finder AppleShowAllFiles TRUE;\killall Finder

取消顯示隱藏的檔案
defaults write com.apple.finder AppleShowAllFiles FALSE;\killall Finder

2016/11/8

spotlight 快速鍵應用

進入spotlight之後,可以用以下的熱鍵應用更多的功能~

  1. command + D  快速查字典
  2. command + L  列出解釋
  3. command + B  在搜尋引擎上搜尋
  4. command + R  找出檔案所屬資料夾
  5. command + I  列出檔案資訊