Linux - dig

dig 指令的意思是 Domain Information Groper,用來查詢有關 DNS server 的資訊,包括域名、IP地址等。

基本語法:

dig [options] [domain]

下 flag 的話,還可以查詢A記錄、CNAME記錄、MX記錄、NS記錄等。

_ga Cookies

  1. Mac Chrome 的 Cookie 在 /Users/weilun/Library/Application Support/Chromium/Default/Cookies 這個位置,可以用 file Cookies 指令查看,發現他是個 SQLite 3.x database 檔。
  2. 如果要在 Chrome 瀏覽器內查看某網頁的 Cookie 的話,在該網頁點擊右上角後,點擊更多工具>開發人員工具>應用程式>儲存空間>Cookie

如果查看 cookie 的話,會發現很多網站都有 key 叫做 _ga 的 cookie,如上圖。

這其實是 Google Analytics cookie,也就是和 Google Analytics 服務做交互時需要用到的 cookie,代表我們使用者。

value 前面的 GA1.3 代表 Google Analytics code 的版本,後面一串是 client id,包含兩部分,第一部分是隨機產生的亂碼,第二部分是使用者進入網站的 timestamp。

這個 client id 是 google 在分析行為時使用者的唯一識別碼,在開發人員工具>網路搜尋 google-analytics,會發現和 google-analytics 服務做交互的 request,並把我們的 client id cookie 也一併傳過去。如上圖所示。

Reference

The Google Analytics Cookie (Explained)

Linux - Monitoring

How linux work 這本書看到了第八章,這一章主要在介紹一些可以監測 CPU / process / 資源 的工具,趁這個機會把其中一些指令記錄下來。

  • lsof : list open files,這個指令會列出使用中的檔案與使用這個檔案的 process
  • top : 可以持續地監看目前所有 process 狀況,包括 PID / CPU / memory / port 等
  • ps : process status,雖然也是列出 process 的狀況,但是是快照的形式而不會持續性變動
  • uptime : kernal 跑了多久、過去 1/5/15 分鐘的 load average

Linux - Symbolic Link

ln -s <path to the file/folder to be linked> <the path of the link to be created>

例如

ln -s hello.txt newhello.txt     

可以用 ls -l 列出檔案查看: 最前面的 l 代表這個檔案是 symlink,後面的箭頭代表這個檔案指向哪個檔案。

unlink <path-to-symlink>

直接使用 rm 指令也行。

find . -type l ! -exec test -e {} \; -print

find -L

- L flag 代表搜索過程中會遵循 symlink,也就是進入 symlink 指向的資料夾/文件作進一步搜索,使用這個 flag 可能會進入無限迴圈,或是不經意地破壞作業系統,應避免使用!

Reference

How can I find broken symlinks Symlink Tutorial in Linux – How to Create and Remove a Symbolic Link

Linux - Shell input & output

把指令的輸出存到某個檔案:

command > file

例如:

echo hello > hello.txt

可以用 cat hello.txt 印出檔案內容。

注意!hello.txt 如果已經存在,會覆蓋掉原本的檔案!

不想覆蓋掉檔案,而是加在原檔案後面的話,將原本的指令的 > 改為 »

例如:

echo hello >> hello.txt

Pipe character

將某指令的輸出當作另一個指定的標準輸入,可以使用 pipe character (|)

例如:

cat hello.txt | wc

wc 會印出會印出他的行數、單詞數、字符串數(包含 newline),會發現是 1, 1, 6 把字串送進檔案、不包含 newline 的另一個作法是這個指令:

printf hello > hello.txt    

Reference

[Linux]cat 搭配wc用法