六月丁香五月婷婷,丁香五月婷婷网,欧美激情网站,日本护士xxxx,禁止18岁天天操夜夜操,18岁禁止1000免费,国产福利无码一区色费

學習啦 > 學習電腦 > 操作系統(tǒng) > Linux教程 >

linux的刪除文件日志命令是什么

時間: 加城1195 分享

  Linux系統(tǒng)下我們經(jīng)常使用到刪除操作,包括刪除文件目錄,日志等,那么用什么命令實現(xiàn)呢,具體有哪些用法?下面由學習啦小編為大家整理了linux的刪除命令的相關(guān)知識,希望對大家有幫助!

  linux的刪除命令實例

  實例一:刪除文件file,系統(tǒng)會先詢問是否刪除。

  命令:

  rm 文件名

  輸出:

  [root@localhost test1]# ll

  總計 4

  -rw-r--r-- 1 root root 56 10-26 14:31 log.log

  root@localhost test1]# rm log.log

  rm:是否刪除 一般文件 “log.log”? y

  root@localhost test1]# ll

  總計 0[root@localhost test1]#

  說明:

  輸入rm log.log命令后,系統(tǒng)會詢問是否刪除,輸入y后就會刪除文件,不想刪除則數(shù)據(jù)n。

  實例二:強行刪除file,系統(tǒng)不再提示。

  命令:

  rm -f log1.log

  輸出:

  [root@localhost test1]# ll

  總計 4

  -rw-r--r-- 1 root root 23 10-26 14:40 log1.log

  [root@localhost test1]# rm -f log1.log

  [root@localhost test1]# ll

  總計 0[root@localhost test1]#

  實例三:刪除任何.log文件;刪除前逐一詢問確認

  命令:

  rm -i *.log

  輸出:

  [root@localhost test1]# ll

  總計 8

  -rw-r--r-- 1 root root 11 10-26 14:45 log1.log

  -rw-r--r-- 1 root root 24 10-26 14:45 log2.log

  [root@localhost test1]# rm -i *.log

  rm:是否刪除 一般文件 “log1.log”? y

  rm:是否刪除 一般文件 “log2.log”? y

  [root@localhost test1]# ll

  總計 0[root@localhost test1]#

  實例四:將 test1子目錄及子目錄中所有檔案刪除

  命令:

  rm -r test1

  輸出:

  復制代碼代碼如下:

  [root@localhost test]# ll

  總計 24drwxr-xr-x 7 root root 4096 10-25 18:07 scf

  drwxr-xr-x 2 root root 4096 10-26 14:51 test1

  drwxr-xr-x 3 root root 4096 10-25 17:44 test2

  drwxrwxrwx 2 root root 4096 10-25 17:46 test3

  drwxr-xr-x 2 root root 4096 10-25 17:56 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]# rm -r test1

  rm:是否進入目錄 “test1”? y

  rm:是否刪除 一般文件 “test1/log3.log”? y

  rm:是否刪除 目錄 “test1”? y

  [root@localhost test]# ll

  總計 20drwxr-xr-x 7 root root 4096 10-25 18:07 scf

  drwxr-xr-x 3 root root 4096 10-25 17:44 test2

  drwxrwxrwx 2 root root 4096 10-25 17:46 test3

  drwxr-xr-x 2 root root 4096 10-25 17:56 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]#

  實例五:rm -rf test2命令會將 test2 子目錄及子目錄中所有檔案刪除,并且不用一一確認

  命令:

  rm -rf test2

  輸出:

  復制代碼代碼如下:

  [root@localhost test]# rm -rf test2

  [root@localhost test]# ll

  總計 16drwxr-xr-x 7 root root 4096 10-25 18:07 scf

  drwxrwxrwx 2 root root 4096 10-25 17:46 test3

  drwxr-xr-x 2 root root 4096 10-25 17:56 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]#

  實例六:刪除以 -f 開頭的文件

  命令:

  rm -- -f

  輸出:

  復制代碼代碼如下:

  [root@localhost test]# touch -- -f

  [root@localhost test]# ls -- -f

  -f[root@localhost test]# rm -- -f

  rm:是否刪除 一般空文件 “-f”? y

  [root@localhost test]# ls -- -f

  ls: -f: 沒有那個文件或目錄

  [root@localhost test]#

  也可以使用下面的操作步驟:

  [root@localhost test]# touch ./-f

  [root@localhost test]# ls ./-f

  ./-f[root@localhost test]# rm ./-f

  rm:是否刪除 一般空文件 “./-f”? y

  [root@localhost test]#

  實例七:自定義回收站功能

  命令:

  myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "$@" $D && echo "moved to $D ok"; }

  輸出:

  復制代碼代碼如下:

  [root@localhost test]# myrm(){ D=/tmp/$(date +%Y%m%d%H%M%S); mkdir -p $D; mv "$@" $D && echo "moved to $D ok"; }

  [root@localhost test]# alias rm='myrm'

  [root@localhost test]# touch 1.log 2.log 3.log

  [root@localhost test]# ll

  總計 16

  -rw-r--r-- 1 root root 0 10-26 15:08 1.log

  -rw-r--r-- 1 root root 0 10-26 15:08 2.log

  -rw-r--r-- 1 root root 0 10-26 15:08 3.log

  drwxr-xr-x 7 root root 4096 10-25 18:07 scf

  drwxrwxrwx 2 root root 4096 10-25 17:46 test3

  drwxr-xr-x 2 root root 4096 10-25 17:56 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]# rm [123].log

  moved to /tmp/20121026150901 ok

  [root@localhost test]# ll

  總計 16drwxr-xr-x 7 root root 4096 10-25 18:07 scf

  drwxrwxrwx 2 root root 4096 10-25 17:46 test3

  drwxr-xr-x 2 root root 4096 10-25 17:56 test4

  drwxr-xr-x 3 root root 4096 10-25 17:56 test5

  [root@localhost test]# ls /tmp/20121026150901/

  1.log 2.log 3.log

  [root@localhost test]#

  相關(guān)閱讀:Linux系統(tǒng)常見故障現(xiàn)象

  1. MBR中g(shù)rub損壞,1_5階段的數(shù)據(jù)損壞,2階段的grub損壞

  2. initramfs*.img文件損壞,內(nèi)核文件損壞

  3. /boot/grub/grub.conf文件丟失

  4. /etc/fstab丟失,無法掛載根等文件系統(tǒng)

  5. /boot 目錄全部的文件丟失

  6. root密碼忘記

  7. 為grub設(shè)置密碼,開機時生效,保護root密碼被惡意修改等

  二、常見故障的分析解決:

  1. 1階段和1_5階段出問題時會開機執(zhí)行完BIOS自檢后直接報錯

  2. 前面兩個階段順利通過,到了執(zhí)行/boot/ 下面的第二個階段時的程序調(diào)用/boot/grub/grub.conf 時文件丟失或者/boot/下內(nèi)核文件和initramfs*.img 文件丟失都會造成卡在第二個階段:丟失initramfs文件時會在過了開機選擇內(nèi)核啟動之后卡住不動,沒有任何提示(在/boot/grub /grub.conf 配置文件中定義了timeout時間,會過了倒計時,然后沒有任何提示)如果是丟失grub.conf 是會進入grub>提示符由管理員指定內(nèi)核文件和initramfs文件位置

  3. /etc/fstab丟失:

  系統(tǒng)可以開機,但是開機時會卡好長時間,因為許多服務(wù)等待超時無法啟動,此時磁盤按照默認以只讀掛載根,這個掛載是在開機時掛載的,因為沒有fstab文件所以無法重新掛載根文件系統(tǒng)以及其他的系統(tǒng),沒有運行級別

  4. 為grub設(shè)置了密碼會在開機進入內(nèi)核啟動時,想要修改grub和內(nèi)核的參數(shù)或者進入系統(tǒng)時需要輸入密碼,當然忘記這樣的密碼也只能使用光盤引導進入救援模式修改配置文件/etc/grub/grub.conf 把相應(yīng)的密碼行刪除即可。

3996324