linux學習筆記--常見命令

linux命令

命令格式

linux命令格式爲:
命令 [ 選項 ] [參數]
[]代表可選

查看幫助文檔

  1. help 可以使用help命令查看幫助文檔 例如: ls --help 或者ls -help
  2. 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

文件磁盤相關命令

  1. 查看文件信息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

  1. 輸出重定向命令
    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

  1. 分屏顯示 more 文件
    文件過大時可以使用more 分屏查看,每次顯示一頁,按下空格翻頁,q停止
    ctrl + b返回上一頁
    ctrl + f查看下一頁
  2. 管道 |
    一個命令的輸出可以通過管道作爲另一個命令的輸入
  3. 清屏 clear
    快捷鍵ctrl + l
  4. 切換目錄 cd
  • cd ~切換到當前用戶的主目錄
  • cd 路徑切換到路徑
  • cd -切換到上次切換的路徑
  • cd .切換到當前目錄
  • cd ..切換到當前目錄的父目錄
  1. 打印當前路徑pwd
  2. 創建目錄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

  1. 刪除目錄rmdir
    rmdir 可以刪除目錄且目錄必須爲空 -p參數可以遞歸刪除
caicai@caicai-VirtualBox:~/mumu$ rmdir cc
rmdir: failed to remove 'cc': Directory not empty

  1. 刪除文件 rm 可以刪除文件或者目錄 要慎重使用rm,rm刪除的文件不可恢復,所以可以使用rm -i逐個詢問刪除,rm -f 強制刪除,要謹慎使用 rm -r遞歸刪除

先記到這裏吧,明天再接着整理,困==

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章