Catherine's blog

Knowledge makes humble, ignorance makes proud.

0%

Linux 基礎指令

整理一下早上進修的學習內容,最近買了新的線上課程 Linux雲端伺服器,用AWS暸解Apache與Nginx,雖然一直都有在使用 Linux ,但為避免有遺漏,針對課程內學習到的新知做一下整理

產生空白資料夾、檔案與命名注意事項(mkdir, touch)

mkdir

使用 mkdir 指令建立目錄時,若相同檔名的資料夾已存在,則會出現錯誤訊息,如下

1
2
$ mkdir ECRWD
mkdir: ECRWD: File exists

一般在 excute shell script 時,若發生此狀況可能造成執行暫停的狀況,如需避免此問題,可以利用 mkdir -p 參數使『建立資料夾已存在』的情況,不要顯示錯誤訊息,使之繼續執行

1
2
$ mkdir -p  ECRWD
$

文字輸出檔案與串連(echo, printf, cat)

echo

印出 “hi”

1
$ echo "hi"

若使用 “>” 將 “hi” 輸出到 1.txt 檔案 ,如將 “hi” 改成 “hello”,再執行一次指令, “hello” 將覆蓋 “hi”

1
$ echo "hi" > 1.txt

若需要接續著寫下去,則可使用 “>>” ,將 “hi” 輸出到 1.txt 檔案 ,如將 “hi” 改成 “hello”,再執行一次指令, 將會出現

1
2
3
4
5
$ echo "hi" > 1.txt
$ echo "hello" >> 1.txt
$ cat 1.txt
hi
hello

Welcome to my other publishing channels