Linux Command Line Basics
基礎操作指令
此內容為 Udacity 上的課程學習筆記:https://classroom.udacity.com/courses/ud595
環境建立
依照課程安裝好軟體後,
vagrant up
:啟動 virtual machine(VM)。
vagrant ssh
:登入 virtual machine(VM)。
exit
or Ctrl+D
:離開、登出。
vagrant init
:初始化 VM 所需文件,當未初始化或是所在資料夾錯誤時都會出現以下錯誤提示。
基礎指令
Ctrl+R
:搜尋過往的 command line。
unzip <file name>
:解壓縮檔案。
cat <file name> <file name>
:concatenate 的意思,將兩個檔案合併起來一起顯示。
wc <file name>
:word count,統計文件裡的字數相關資訊,分別顯示「行數」、「字數」、「檔案大小(bytes)」、「檔案名稱」。
dif <file name> <file name>
:比較並列出兩個檔案內容的不同之處。
man <command>
:manual,可查看指令的定義文件。
ls -a
:不忽略.
開頭的檔案,例如 .DS_Store
。
rm -rf /
:刪除整個 Linux 底下所有的資料夾以及內容。
rm
:移除檔案或資料夾。-r
:刪除資料夾以及其內容物。-f
:強制執行。
less <file name>
:用來瀏覽文件的程式,參考 http://sheet.shiar.nl/less
nano <file name>
:編輯文件。
Filesystem tree
命名彈性很大,可以用 !$#()[]%&以及空格,但要注意當有上述幾種符號時,命名要加上 quotes(’)或是 escaped:
預計檔名:Great Filename!
quoted:'Great Filename!'
escaped:Great\ Filename\!
pwd
:print working directory,顯示當下的資料夾路徑。
cd <檔案路徑>
:直接寫上路徑(absolute path),到達該資料夾。
cd <該資料夾底下的資料夾>
:往下一層資料夾(relative path)。
移動、複製檔案與建立、刪除資料夾
mv <filename1> <filename2> ... <directory>
:移動檔案至特定資料夾。
cp <filename1> <filename2> ... <directory>
:複製檔案至特定資料夾。
mkdir <directory name>
:建立資料夾。
rmdir <directory name>
:移除資料夾,若資料夾內有其他檔案則無法刪除。
rm -r <directory name>
:移除資料夾以及資料夾內的檔案。
比對檔名
*
:萬用字元,範例如下
{…,…,…}
:多條件比對。
?
:比對任意字元,一個 ?
代表一個字元。
[…]
:比對符合括弧內任一字元的檔名。
注意大小寫是為不同比對條件:
綜合練習: