發表文章

Linux FAQ : mount 掛載 iso 到主機

  參考 : https://richarlin.tw/blog/linux-mount/ https://unix.stackexchange.com/questions/30637/mount-error-is-not-a-block-device 何時會需要此指令 離線升級套件 磁碟區共享 有時要更新一些 套件 會用 yum 等指令 不過有時沒網路 或是 找不到更新包網站 這時可以用離線方式 離線需要準備 os 相關安裝光碟 把安裝光碟掛載到主機上 就可以使用 離線安裝套件 常用 mount 來源磁碟目錄 要掛載到哪一個目錄 轉移 mount 目錄 mount --bind <olddir> <mountpoint> 異常 錯誤 : mount error "is not a block device" mount error "is not a block device" mount 將包含文件系統的塊存儲設備附加到目錄,這不是您要嘗試執行的操作,因此會出現錯誤消息。您想要的是創建從新目錄名稱到舊現有名稱的鏈接 可以改使用 ln 或是 移轉 : mount --bind <olddir> <mountpoint> mount 與 ln 區別 如果需要目錄的用戶無法訪問它,或者磁盤不支持軟鏈接 掛載綁定很有用。綁定更強大,會更頻繁地工作。綁定工作是因為內核對應用程序“撒謊”,並告訴它一個目錄包含實際上在其他地方的內容。但是,除非您將綁定添加到/etc/fstab. 如果有疑問,我們 ln -s- 它更容易,更靈活,不需要 root,會告訴您實際目錄在哪裡等。您通常不需要綁定 mount hang 住 , 卡住 ... 等 會造成甚麼影響 df 卡住大多是掛載磁碟異常 ( mount ) 可以改使用 df -l ( 查看本地磁碟 ) 查看掛載磁碟 mount | column -t 參考 : https://www.gushiciku.cn/pl/pIst/zh-tw 取消掛載磁碟 umount 位置 umount /T100_gr umount -f /T100_gr

Linux FAQ : 給予顯示文字色彩

  Linux FAQ : 給予顯示文字色彩 參考 : https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux https://www.codegrepper.com/code-examples/shell/bash+echo+color You can use these  ANSI escape codes : Black 0;30 Dark Gray 1;30 Red 0;31 Light Red 1;31 Green 0;32 Light Green 1;32 Brown/Orange 0;33 Yellow 1;33 Blue 0;34 Light Blue 1;34 Purple 0;35 Light Purple 1;35 Cyan 0;36 Light Cyan 1;36 Light Gray 0;37 White 1;37 範例 : 方案 1 : shell script RED='\\033[0;31m' #設定改變色彩 NC='\\033[0m' # 還原用讓後面字詞不改變 echo -e "I ${RED}love${NC} Stack Overflow\\n" 方案 2 : echo -e "I \033[0;31mlove\033[0m Stack Overflow\n"

Linux FAQ : grep 搜尋檔案內容

  Linux FAQ : grep 搜尋檔案內容 1. 基本使用 grep 關鍵字 檔案1 檔案2 ... 2. grep 亦可搭配萬⽤字元( * )同時搜尋多個檔案, 例如在 /etc/ ⽬錄之下所有 *.conf 檔案中,尋找 network 這個字眼 grep network /etc/*.conf 參數 grep -i 不區分大小寫 grep -v 排除條件顯示 grep -l 顯示符合的檔名 grep -n 顯示條件在第幾行 grep -q 顯示 0 , 1 ( 檢查 $? , 0 is successful ) grep -x 整行完全符合才顯示 找出字詞是 1 byte 以上 ( 中文 , 日文 ... 等 ) grep -P -aobn '[^\x00-\x7F]' 找出 ORACLE tnsnames.ora 對應 HOST 資訊 grep -A 10 "topprd" $ORACLE_HOME/network/admin/tnsnames.ora | sed -n '/ADDRESS/, /ADDRESS/p' | grep HOST | awk -F 'HOST =' '{print $2}' | awk -F ')' '{print $1}' | sed -n '1,1p'

Linux FAQ : find 用法

  Linux FAQ : find 用法 find 目錄 參數 條件 參考 : https://blog.gtwang.org/linux/unix-linux-find-command-examples/ https://stackoverflow.com/questions/4210042/how-do-i-exclude-a-directory-when-using-find find . -type d 'xxx*' 參數 目錄搜尋層數 maxdepth 第幾層 find . -maxdepth 1 忽略特定目錄 -not -path 目錄 find . -name '123' -not -path './usr/*' path 目錄 -prune -o find . -path ./usr -prune -o -name '123' -user 使用者 find . -user topstd -name '*' -exec ls -l {} \\; 排除 使用者 find . ! -user topstd -name '*' -exec ls -l {} \\; -szie 大小 find . -size +10k 小於 10 k find . -size -10k https://stackoverflow.com/questions/38843212/how-to-use-echo-with-find-in-bash The shell redirection, >> is being done at first, a file named {} is being created before even the find starts and the strings (the number of files are in there) are being written to the file {}. You need: find . -type f -exec bash -c 'echo "This file found" >>"$1"' _ {} \\;

Linux FAQ : ps 顯示的 stat 簡介

  Linux FAQ : ps 顯示的 stat 簡介 參考 : https://unix.stackexchange.com/questions/18474/what-does-this-process-stat-indicates 狀態 D (uninterruptible sleep) 在不可中斷的休眠中 (一般為正在進行輸入/輸出) 通常是 IO R (running) 在運行中或可以被運行 (即在運行序列 run queue) S (sleeping) 在可以被中斷的休眠中 (一般是正在等待某事件完結) T (traced or stopped) 已被停止。因工作控制訊號 (job control signal) 或Process在被追蹤中。 Z (Zombie) 不能運作的進程,即所謂殭屍進程。一般因為已終止但未能被其母進程成功接收的進程。 附加的選項 < 高優先級(對其他用戶不利) N 低優先級(對其他用戶很好) L 已將頁面鎖定在內存中(用於實時和自定義IO) s 是會議負責人 l 是多線程的(使用CLONE_THREAD,就像NPTL pthreads一樣) + 在前台進程組中 例子 登入 : Ss sshd: test [priv] S sshd: test@pts/2 執行查看指令 : R+ ps -e -o stat,command,pid 其他 : S<l : /usr/bin/pulseaudio --start Ss :  oracletopprd (LOCAL=NO) Ssl : /usr/libexec/upowerd 用法範例 排序 預設是從小開始 --sort= 指令加 - 會反向 原本 --sort ( 0 , 1 , 2 ... ) 反向 --sort=- ( 99 , 98 ... ) 系統上最耗費記憶體的程式 ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head 這行指令可利用 ps 指令列出行程的一些基本資訊, 按照每個行程所使用的記憶體排序後,列出排名最前面的幾個行程

Linux FAQ : sed 指令 ( 取代 , 截取行 )

圖片
 參考 :  https://www.notion.so/sed-552c73cc21424524a68896aba442f5e4#06a84ad623b4419080889264dbd6218e 删除文件第一行: sed -i '1d' filename 删除文件最后一行: sed -i '$d' fileName 刪除首行空白 sed 's/^[ \t]*//g'

Linux FAQ : 查看 jar 檔方式

圖片
jar 檔其實類似 zip 壓縮檔  除了可以用 zip 軟體來打開 在 Linux 可以用一些指令輔助 參考 : https://www.unix.com/unix-for-advanced-and-expert-users/163550-how-read-file-inside-jar.html 1. 查看 jar 裡面檔案內容 unzip -p jar 檔 要查看的檔案 範例 : unzip -p utilitytools.jar META-INF/MANIFEST.MF 2. 查看 jar 有哪些檔案 jar -tf jar 檔 範例 : jar -tf utilitytools.jar | grep MANIFEST.MF 3. 顯示檔案詳細資訊 jar -tvf jar檔 範例 : jar -tvf utilitytools.jar | grep MANIFEST.MF