linux命令
命令格式
linux命令格式爲:
命令 [ 選項 ] [參數]
[]代表可選
查看幫助文檔
help
可以使用help命令查看幫助文檔 例如:ls --help
或者ls -help
man
manual 手冊,是linux提供的一個手冊,包含了大多數命令 可以使用man 命令
來查看命令的用法,例如man ls
自動補全
和很多地方的快捷鍵一樣,使用tab鍵自動補全,當有唯一的時,會直接自動補全,當不唯一時,第一次按tab鍵沒有反應,當按下第二次tab鍵時,會顯示可選擇的,當輸入不重複的字符,再次按下tab鍵,會自動補全
查看歷史命令
history
使用history可以查看已經輸入過的命令,例如:
caicai@caicai-VirtualBox:~$ history
1 mocp
2 su
3 sudo moc
4 sudo apt install moc
5 sudo ./VBoxLinuxAdditions.run
6 gedit a.txt
7 ll
8 sudo apt-get install virtual-box-guest-x11
9 VBoxClient-all
10 sudo apt-get install virtual-box-guest-x11
文件磁盤相關命令
- 查看文件信息
ls
list的簡寫功能是列出目錄文件
ls -a
列出所有文件包括隱藏的
caicai@caicai-VirtualBox:~$ ls
1 Documents examples.desktop Music Public Videos
Desktop Downloads mumu Pictures Templates
caicai@caicai-VirtualBox:~$ ls -a
. Downloads Public
.. examples.desktop .ssh
1 .gnupg .sudo_as_admin_successful
.bash_history .ICEauthority Templates
.bash_logout .local .thunderbird
.bashrc .mozilla .vboxclient-clipboard.pid
.cache mumu .vboxclient-display.pid
.config Music .vboxclient-draganddrop.pid
.dbus Pictures .vboxclient-seamless.pid
Desktop .presage Videos
Documents .profile .xinputrc
ls -l
以列表的形式顯示文件的詳細信息
caicai@caicai-VirtualBox:~$ ls -l
total 52
drwxr-xr-x 2 caicai caicai 4096 10月 16 09:19 1
drwxr-xr-x 2 caicai caicai 4096 10月 16 09:19 Desktop
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Documents
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Downloads
-rw-r--r-- 1 caicai caicai 8980 10月 15 15:34 examples.desktop
drwxr-xr-x 3 caicai caicai 4096 10月 16 20:07 mumu
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Music
drwxr-xr-x 2 caicai caicai 4096 10月 16 14:39 Pictures
drwxr-xr-x 2 caicai caicai 4096 10月 15 19:15 Public
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Templates
drwxr-xr-x 2 caicai caicai 4096 10月 15 16:00 Videos
ls -lh
友好的顯示文件詳細信息
caicai@caicai-VirtualBox:~$ ls -lh
total 52K
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 09:19 1
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 09:19 Desktop
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Documents
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Downloads
-rw-r--r-- 1 caicai caicai 8.8K 10月 15 15:34 examples.desktop
drwxr-xr-x 3 caicai caicai 4.0K 10月 16 20:07 mumu
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Music
drwxr-xr-x 2 caicai caicai 4.0K 10月 16 14:39 Pictures
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 19:15 Public
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Templates
drwxr-xr-x 2 caicai caicai 4.0K 10月 15 16:00 Videos
- 輸出重定向命令
linux允許將命令執行結果重定向到文件中
注意:>會覆蓋原來的,>>00000000是追加 =
例如ls >ls.txt
caicai@caicai-VirtualBox:~$ ls
1 Documents examples.desktop mumu Pictures Templates
Desktop Downloads ls.txt Music Public Videos
caicai@caicai-VirtualBox:~$ more ls.txt
1
Desktop
Documents
Downloads
examples.desktop
ls.txt
mumu
Music
Pictures
Public
Templates
Videos
- 分屏顯示
more 文件
文件過大時可以使用more 分屏查看,每次顯示一頁,按下空格翻頁,q停止
ctrl + b返回上一頁
ctrl + f查看下一頁 - 管道 |
一個命令的輸出可以通過管道作爲另一個命令的輸入 - 清屏
clear
快捷鍵ctrl + l - 切換目錄
cd
cd ~
切換到當前用戶的主目錄cd 路徑
切換到路徑cd -
切換到上次切換的路徑cd .
切換到當前目錄cd ..
切換到當前目錄的父目錄
- 打印當前路徑
pwd
- 創建目錄
mkdir
mkdir
命令可以創建一個新目錄 參數-p 可以遞歸創建目錄
例如:
caicai@caicai-VirtualBox:~/mumu$ mkdir -p cc/mm/love
caicai@caicai-VirtualBox:~/mumu$ tree
├── a.txt
├── caicai
│ └── a.txt
└── cc
└── mm
└── love
- 刪除目錄
rmdir
rmdir
可以刪除目錄且目錄必須爲空-p
參數可以遞歸刪除
caicai@caicai-VirtualBox:~/mumu$ rmdir cc
rmdir: failed to remove 'cc': Directory not empty
- 刪除文件
rm
可以刪除文件或者目錄 要慎重使用rm,rm刪除的文件不可恢復,所以可以使用rm -i逐個詢問刪除,rm -f 強制刪除,要謹慎使用 rm -r遞歸刪除
先記到這裏吧,明天再接着整理,困==