# Linux 备忘

By [dydx](https://paragraph.com/@dydx-3) · 2022-01-15

---

`程序从哪读数据 FD`

0<， < 1>, > 2>

ls main.sh no.such.file >file.txt 2>&1 <==> ls main.sh no.such.file >&file.txt <==> ls main no.such.file &>file.txt

set -o noclobber -- 打开禁用覆写，关闭 +o echo “hello“ >| file.txt --临时可以覆盖写

sudo su - root -c 'ls -al' -- 切换

command options arguments -- 先替换，再重组

wildcard
--------

別忘了"擴充+重組"這個重要特性, 而且只作用在 argument 的 path 上.

*   \* -- 0 或 多个字符， 以 \* 或 ? 開首的 wildcard 不能匹配隱藏文件，但 1\*txt 及 1?txt 均可匹配 1.txt 這樣的路逕名稱
    
*   ? -- 1个字符
    
*   \[list\] -- 匹配 \`list\`里的任何一个字符
    
*   \[!list\] -- 不匹配 \`list\`里的任何一个字符，!放其它地方需要转义 \\!
    
*   {str1,str2,str3} -- {,str1}，也可以为空, 逗号之间不能有空格
    

mkdir -p test; cd $\_

array=($(echo "abcdefghijkl"|sed 's/../ &/g'))

od -c filename

‘‘ -- 忽略所有关闭的meta chars

““ -- 忽略所有的关闭字符 meta chars，除了 $, ‘, \\

在 bash 中，常用的 quoting 有如下三種方法：

*   hard quote：' ' (單引號)，凡在 hard quote 中的所有 meta 均被關閉。
    
*   soft quote： " " (雙引號)，在 soft quoe 中大部份 meta 都會被關閉，但某些則保留(如 $ )。(註二)
    
*   escape ： \\ (反斜線)，只有緊接在 escape (跳脫字符)之後的單一 meta 才被關閉。 ( 註二：在 soft quote 中被豁免的具體 meta 清單，我不完全知道， 有待大家補充，或透過實作來發現及理解。 )

---

*Originally published on [dydx](https://paragraph.com/@dydx-3/linux)*
