目錄資訊查看#
目錄查看命令#
語法:
ls [-alrtAFR] [name...]
參數:
- -a 顯示所有文件及目錄 (以。開頭的隱藏文件也會列出)
- -d 只列出目錄(不遞迴列出目錄內的文件)。
- -l 以長格式顯示文件和目錄資訊,包括權限、所有者、大小、創建時間等。
- -r 倒序顯示文件和目錄。
- -t 將按照修改時間排序,最新的文件在最前面。
- -A 同 -a ,但不列出 "." (目前目錄) 及 ".." (父目錄)
- -F 在列出的文件名稱後加一符號;例如可執行檔則加 "*", 目錄則加 "/"
- -R 遞迴顯示目錄中的所有文件和子目錄。
範例:
ls -l
輸出:
總用量 12
drwxr-xr-x 2 user user 4096 6月 23 09:30 Documents
drwxr-xr-x 2 user user 4096 6月 23 09:30 Pictures
drwxr-xr-x 2 user user 4096 6月 23 09:30 Videos
-rw-r--r-- 1 user user 0 6月 23 09:30 file1.txt
目錄切換命令#
語法:
cd [dirName]
參數:
-
dirName 要切換的目標目錄。
-
~ 跳到自己的 home 目錄
-
../.. 上兩級目錄
範例:
cd /home/user/Documents
當前路徑顯示命令#
語法:
pwd
範例:
pwd
輸出:
/home/user/Documents
系統資訊查看命令#
語法:
uname
範例:
uname
輸出:
Linux
清理螢幕命令#
語法:
clear
範例:
clear
顯示文件內容命令#
語法:
cat [file...]
參數:
- file 要顯示內容的文件。
範例:
cat file1.txt
輸出:
Hello, world!
切換用戶身份命令#
語法:
sudo [command]
參數:
- command 要以管理員身份執行的命令。
範例:
sudo apt-get update
文件拷貝命令#
語法:
cp [option] source destination
參數:
-
-i, --interactive 在覆蓋文件前進行確認。
-
-v, --verbose 顯示拷貝過程中的詳細資訊。
-
source 要拷貝的源文件或目錄。
-
destination 目標文件或目錄。
範例:
cp file1.txt file2.txt
切換用戶命令#
語法:
su [user]
參數:
- user 要切換到的用戶。
範例:
su user2
移動文件命令#
語法:
mv [option] source destination
參數:
-
-i, --interactive 在覆蓋文件前進行確認。
-
-v, --verbose 顯示移動過程中的詳細資訊。
-
source 要移動的源文件或目錄。
-
destination 目標文件或目錄。
範例:
mv file1.txt /home/user/Documents
創建文件夾命令#
語法:
mkdir [option] directory...
參數:
-
-p, --parents 創建父目錄(如果不存在)。
-
directory 要創建的目錄。
範例:
mkdir documents
創建文件命令#
語法:
touch [option] file...
參數:
-
-a, --time=atime 修改訪問時間。
-
-c, --no-create 不創建新文件。
-
-m, --time=mtime 修改修改時間。
-
-r, --reference=FILE 使用指定文件的時間資訊。
-
file 要創建的文件。
範例:
touch file1.txt
刪除命令#
語法:
rm [option] file...
參數:
-
-f, --force 忽略不存在的文件,不顯示警告。
-
-i, --interactive 進行確認提示。
-
-r, -R, --recursive 遞迴刪除目錄及其內容。
-
file 要刪除的文件或目錄。
範例:
rm file1.txt
目錄刪除命令#
語法:
rmdir [option] directory...
參數:
-
-p, --parents 刪除父目錄(如果為空)。
-
directory 要刪除的目錄。
範例:
rmdir documents
顯示網路配置信息命令#
語法:
ifconfig
範例:
ifconfig
輸出:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::c6e9:84ff:fe87:6835 prefixlen 64 scopeid 0x20<link>
ether c4:e9:84:87:68:35 txqueuelen 1000 (Ethernet)
RX packets 45574 bytes 33661624 (33.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23257 bytes 2469127 (2.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
重啟命令#
語法:
reboot
範例:
reboot
關機命令#
語法:
poweroff
範例:
poweroff
系統幫助命令#
語法:
man [command]
參數:
- command 要查看幫助的命令。
範例:
man ls
數據同步寫入磁碟命令#
語法:
sync
範例:
sync
查找文件命令#
語法:
find [path...] [expression]
參數:
- path 要查找的路徑。
- expression 要匹配的表達式。
範例:
find /home/user -name "*.txt"
輸出:
/home/user/Documents/file1.txt
/home/user/Documents/file2.txt
查找內容命令#
語法:
grep [option] pattern [file...]
參數:
-
-i, --ignore-case 忽略大小寫。
-
-r, --recursive 遞迴查找目錄中的文件。
-
-l, --files-with-matches 只顯示包含匹配項的文件名。
-
pattern 要查找的模式。
-
file 要查找的文件。
範例:
grep "Hello" file1.txt
輸出:
Hello, world!
文件夾大小查看命令#
語法:
du [option] [directory...]
參數:
-
-s, --summarize 只顯示總大小。
-
-h, --human-readable 以人類可讀的格式顯示大小。
-
directory 要查看大小的目錄。
範例:
du -sh /home/user/Documents
輸出:
4.0K /home/user/Documents
磁碟空間檢查命令#
語法:
df [option] [file...]
參數:
-
-h, --human-readable 以人類可讀的格式顯示大小。
-
file 要檢查空間的文件。
範例:
df -h
輸出:
文件系統 容量 已用 可用 已用% 挂載點
/dev/sda1 100G 50G 50G 50% /
使用 gedit 打開某個文件命令#
語法:
gedit [file...]
參數:
- file:要打開的文件。
範例:
gedit file1.txt
當前的系統進程查看命令#
語法:
ps [option]
參數:
- -a, --all:顯示所有進程,包括其他用戶的進程。
- -u, --user=USER:只顯示指定用戶的進程。
- -x, --deselect:不顯示與終端相關的進程。
- -e:等價於 -A,顯示所有進程。
- -f:顯示詳細進程資訊。
- -l:以長格式顯示進程資訊。
- -p PID:只顯示指定 PID 的進程。
- -U, --userlist=USERLIST:顯示指定用戶列表的進程。
範例:
ps -ef
輸出:
UID
PID PPID C STIME TTY TIME CMD
root 1 0 0 09:30 ? 00:00:01 /sbin/init
root 2 0 0 09:30 ? 00:00:00 [kthreadd]
root 3 2 0 09:30 ? 00:00:00 [rcu_gp]
...
進程實時運行狀態查看命令#
語法:
top
範例:
top
文件類型查看命令#
語法:
file [file...]
參數:
- file:要查看類型的文件。
範例:
file file1.txt
輸出:
file1.txt: ASCII text
此文由 Mix Space 同步更新至 xLog
原始鏈接為 https://api.xn--i2r.cc/posts/Linux-Study/LS1