linux commands

basic

command
command arguments
command -options
command -options arguments
command --long_form_options
cd <path>
ls
ls -alh  # -a 顯示隱藏黨 -l 使用長格式 -h 檔案大小使用人類可讀
ls -l --sort=time  # 以時間做排序
ls -l --sort=size  # 以大小做排序
pwd
touch <file>  # 創建檔案/更新檔案時間
file <file>  # 可以查看檔案的實際類型
mkdir <directory>
mkdir -p <directory>  # 多層式創建資料夾
rm <file>  # 移除檔案
rm -d  <dir>  # 刪除空資料夾(或者用rmdir <dir>)
rm -r  <dir>  # 遞迴刪除
rm -i  # 互動式
rm -rf  # 遞迴強制刪除

mv <source> <destination>  # 移動或重命名檔案或資料夾,移動可一次移動多個

cp mv <source> <destination>  #複製文件
cp -r mv <source> <destination>  # 複製整個資料夾
clear  # 清除畫面輸出

histroy  # 列出歷史紀錄命令

查看指令類型(type)

type <arguments>
type clear  # An executable program (is heahed)
type mkdir
type cd  # A built-in shell command
type cow  # An alias

手冊(man)

man arguments  # 查詢某指令的手冊
man -k <arguments>  # 查詢特定關鍵字
man <number> <arguments>  # 查詢特定指令的第一章節

幫助(help)

help arguments  # 如果一個指令是 built-in,則必須使用 help 查看  (例如 cd pwd export)

查詢指令位置(which)

which <arguments>
which clear

顯示日期(data/cal/ncal)

date

cal

ncal
ncal 2024
ncal july 2024
ncal -A 1 -B 2
ncal -A1 -B2

迴響(echo)

echo string

env  # 顯示環境變數 (需要加 $)
prinenv  # 顯示環境變數 (不用加 $)

環境變數

export

排序(sort)

sort <file>
sort -r -u <file>
sort -ru <file>
sort --reverse --unique <file>

以 GUI 方式開啟目錄(xdg-open)

xdg-open ~

編輯檔案(nano)

nano <file>  # 如果檔案不存在會創建