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

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/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 + $ : 從目前的地方複製到最後面

...以此類推。