debugfs linux rm 刪除 恢復 Attempt to read block from filesystem resulted in short read while opening fi

 

 

wphp

 

 

刪除具備空字符的文件node

反斜槓來轉義下一個字符linux

rm -R  Samples\ -\ Copy 

well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ ls
Client.php  Exception.php  Function.Business.php  Interface.php  Mock  Mock.php  Model  Model.php  Samples  Samples - Copy  Show
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ cp -R Samples Samples_rm
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ ls
Client.php  Exception.php  Function.Business.php  Interface.php  Mock  Mock.php  Model  Model.php  Samples  Samples - Copy  Samples_rm  Show
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ cd Samples/ -/ Copy 
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders/Samples$ cd ..
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ cd Samples\ -\ Copy 
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders/Samples - Copy$ cd ..
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ cd Samples\ -\ Copy 
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders/Samples - Copy$ cd ..
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ rm -R  Samples\ -\ Copy 
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ ll
total 112
drwxr-xr-x 7 well well  4096 May  4 20:21 ./
drwxr-xr-x 3 root root  4096 May  4 19:45 ../
-rwxrwxrwx 1 well well 36520 Apr 10 12:03 Client.php*
-rwxrwxrwx 1 well well  5033 Mar  2 12:41 Exception.php*
-rwxrwxrwx 1 well well  3542 Apr 24 16:24 Function.Business.php*
-rwxrwxrwx 1 well well  4708 Mar  2 12:41 Interface.php*
drwxrwxrwx 2 well well  4096 May  4 19:47 Mock/
-rwxrwxrwx 1 well well  6437 Mar  2 12:41 Mock.php*
drwxrwxrwx 2 well well  4096 May  4 19:47 Model/
-rwxrwxrwx 1 well well 17734 Mar  2 12:41 Model.php*
drwxrwxrwx 2 well well  4096 May  4 20:13 Samples/
drwxrwxr-x 2 well well  4096 May  4 20:18 Samples_rm/
drwxrwxrwx 2 well well  4096 Apr 10 09:51 Show/
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ 

 

 

Linux下如何處理包含空格和特殊字符的文件名 - 51CTO.COM
http://os.51cto.com/art/201507/483983_all.htmshell

Linux下如何處理包含空格和特殊字符的文件名
2015-07-13 11:28 Avishek Kumar LCTT 字號:T | T
一鍵收藏,隨時查看,分享好友!
咱們常常會看到文件名和文件夾名。大多數時候文件/文件夾的名字和內容相關並以數字和字母開頭。字母加數字的文件名最多見,應用也很普遍,但總會須要處理一些包含特殊字符的文件名/文件夾名。本文做者已經嘗試覆蓋你可能碰到的全部狀況。大多數測試都在BASH Shell裏完成,可能在其餘shell下會有差別。 
咱們常常會看到文件名和文件夾名。大多數時候文件/文件夾的名字和內容相關並以數字和字母開頭。字母加數字的文件名最多見,應用也很普遍,但總會須要處理一些包含特殊字符的文件名/文件夾名。vim

注意:咱們可能有各類類型的文件,可是爲了簡單以及方便實現,在本文中咱們只用文本文件(.txt)作演示。c#

 

最多見的文件名例子:api

abc.txt
avi.txt
debian.txt
...
數字文件名例子:bash

121.txt
3221.txt
674659.txt
...
字母數字文件名例子:app

eg84235.txt
3kf43nl2.txt
2323ddw.txt
...
包含特殊字符的文件名的例子,並不常見:編輯器

#232.txt
#bkf.txt
#bjsd3469.txt
#121nkfd.txt
-2232.txt
-fbjdew.txt
-gi32kj.txt
--321.txt
--bk34.txt
...
一個顯而易見的問題是 - 在這個星球上有誰會建立和處理包含井號(#),分號(;),破折號(-)或其餘特殊字符的文件/文件夾啊!

我和你想的同樣,這種文件名確實不常見,不過在你必須得處理這種文件名的時候你的 shell 也不該該出錯或罷工。並且技術上來講,Linux 下的一切好比文件夾、驅動器或其餘全部的都被看成文件處理。

處理名字包含破折號(-)的文件
建立以破折號(-)開頭的文件,好比 -abx.txt。

$ touch -abc.txt
測試輸出
touch: invalid option -- 'b'
Try 'touch --help' for more information.
出現上面錯誤的緣由是,shell 把破折號(-)以後的內容認做參數了,而很明顯沒有這樣的參數,因此報錯。

要解決這個問題,咱們得告訴 Bash shell(是的,這裏以及本文後面的大多數例子都是基於 BASH 環境)不要將特殊字符(這裏是破折號)後的字符解釋爲參數。

有兩種方法解決這個錯誤:

$ touch -- -abc.txt [方法 #1]
$ touch ./-abc.txt [方法 #2]
你能夠經過運行命令 ls 或 ls -l 列出詳細信息來檢查經過上面兩種方式建立的文件。

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 11:05 -abc.txt
要編輯上述文件能夠這樣:

$ nano -- -abc.txt
或者
$ nano ./-abc.txt
注意:你能夠將 nano 替換爲任何其餘你喜歡的編輯器好比說 vim:

$ vim -- -abc.txt
或者
$ vim ./-abc.txt
若是隻是簡單地移動文件能夠這樣:

$ mv -- -abc.txt -a.txt
或者
$ mv -- -a.txt -abc.txt
刪除這種文件,能夠這樣:

$ rm -- -abc.txt
或者
$ rm ./-abc.txt
若是一個目錄下有大量這種名字包含破折號的文件,要一次所有刪除的話,能夠這樣:

$ rm ./-*
重要:

上面討論的規則能夠一樣應用於名字中包含任意數量以及任意位置的鏈接符號的文件。就是說,-a-b-c.txt,ab-c.txt,abc-.txt,等等。

上面討論的規則能夠一樣應用於名字中包含任意數量以及任意位置鏈接符號的文件夾,除了一種狀況,在刪除一個文件夾的時候你得這樣使用rm -rf:

$ rm -rf -- -abc 或者 $ rm -rf ./-abc

處理名字包含井號(#)的文件
符號#在 BASH 裏有很是特別的含義。#以後的一切都會被認爲是評論,所以會被 BASH 忽略。

經過例子來加深理解:

建立一個名字是 #abc.txt 的文件:

$ touch #abc.txt
測試輸出
touch: missing file operand
Try 'touch --help' for more information.
出現上面錯誤的緣由是,BASH 將 #abc.txt 解釋爲評論而忽略了。因此命令 touch沒有收到任何文件做爲參數,因此致使這個錯誤。

要解決這個問題,你可能須要告訴 BASH 不要將 # 解釋爲評論。

$ touch ./#abc.txt
或者
$ touch '#abc.txt'
檢查剛建立的文件:

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 12:14 #abc.txt
如今建立名字中除了開頭的其餘地方包含 # 的文件。

$ touch ./a#bc.txt
$ touch ./abc#.txt
或者
$ touch 'a#bc.txt'
$ touch 'abc#.txt'
運行 ‘ls -l‘ 來檢查:

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 12:16 a#bc.txt
-rw-r--r-- 1 avi avi 0 Jun 8 12:16 abc#.txt
若是同時建立兩個文件(好比 a 和 #bc)會怎麼樣:

$ touch a.txt #bc.txt
檢查剛建立的文件:

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 12:18 a.txt
很明顯上面的例子中只建立了文件 a 而文件 #bc 被忽略了。對於上面的狀況咱們能夠這樣作,

$ touch a.txt ./#bc.txt
或者
$ touch a.txt '#bc.txt'
檢查一下:

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 12:20 a.txt
-rw-r--r-- 1 avi avi 0 Jun 8 12:20 #bc.txt
能夠這樣移動文件:

$ mv ./#bc.txt ./#cd.txt
或者
$ mv '#bc.txt' '#cd.txt'
這樣拷貝:

$ cp ./#cd.txt ./#de.txt
或者
$ cp '#cd.txt' '#de.txt'
可使用你喜歡的編輯器來編輯文件:

$ vi ./#cd.txt
或者
$ vi '#cd.txt'

$ nano ./#cd.txt
或者
$ nano '#cd.txt'
這樣刪除:

$ rm ./#bc.txt
或者
$ rm '#bc.txt'
要刪除全部以井號(#)開頭的文件,能夠這樣:

# rm ./#*
處理名字包含分號(;)的文件
若是你還不知道的話,分號在 BASH 裏起到命令分隔的做用,其餘 shell 可能也是同樣的。分號做爲分隔符可讓你一次執行幾個命令。你碰到過名字包含分號的文件嗎?若是沒有的話,這裏有例子。

建立一個名字包含分號的文件。

$ touch ;abc.txt
測試輸出
touch: missing file operand
Try 'touch --help' for more information.
bash: abc.txt: command not found
出現上面錯誤的緣由是,在運行上面命令的時候 BASH 會把 touch 解釋爲一個命令可是在分號前沒有任何文件參數,因此報告錯誤。而後報告的另外一個錯誤找不到命令 abc.txt,只是由於在分號後 BASH 會指望另外一個新的命令,而 abc.txt 並非一個命令。

要解決這個問題,咱們得告訴 BASH 不要將分號解釋爲命令分隔符,例如:

$ touch ./';abc.txt'
或者
$ touch ';abc.txt'
注意:咱們將文件名用單引號 '' 包含起來。這樣能夠告訴 BASH 分號 ; 是文件名的一部分而不是命令分隔符。

對名字包含分號的文件和文件夾的其餘操做(就是,拷貝、移動、刪除)能夠直接將名字用單引號包含起來就行了。

處理名字包含其餘特殊字符的文件/文件夾
文件名包含加號 (+)
不須要任何特殊處理,按平時的方式作就行了,好比下面測試的文件名。

$ touch +12.txt
文件名包含美圓符 ($)
你須要將文件名用單引號括起來,像處理分號那樣的方式。而後就很簡單了。

$ touch '$12.txt'
文件名包含百分號 (%)
不須要任何特殊處理,看成一個普通文件就能夠了。

$ touch %12.txt
文件名包含星號 (*)
須要用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改。)

$ touch *12.txt
注意:當你須要刪除星號開頭的文件時,千萬不要用相似下面的命令。

$ rm *
或者
$ rm -rf *
而是用這樣的命令,(LCTT 譯註:此處原文有誤,已修改)

$ rm ./'*.txt'
文件名包含歎號 (!)
只要將文件名用單引號括起來,其餘的就同樣了。

$ touch '!12.txt'
文件名包含小老鼠 (@)
沒有什麼特別的,能夠將名字包含小老鼠的文件看成普通文件。

$ touch '@12.txt'
文件名包含 ^
不須要特殊處理。能夠將名字包含 ^ 的文件看成普通文件。

$ touch ^12.txt
文件名包含 (&)
將文件名用單引號括起來,而後就能夠操做了。

$ touch '&12.txt'
文件名包含括號 ()
若是文件名包含括號,你須要將文件名用單引號括起來。

$ touch '(12.txt)'
文件名包含花括號 {}
用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改)

$ touch '{12.txt}'
文件名包含尖括號 <>
名字包含尖括號的文件須要用單引號括起來。

$ touch '<12.txt>'
文件名包含方括號 [ ]
用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改)

$ touch '[12.txt]'
文件名包含下劃線 (_)
這個很是廣泛,不須要特殊對待。看成普通文件隨意處理。

$ touch _12.txt
文件名包含等號 (=)
用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改)

$ touch '=12.txt'
處理反斜槓 ()
反斜槓會告訴 shell 忽略後面字符的特殊含義。你必須將文件名用單引號括起來,就像處理分號那樣。其餘的就沒什麼了。

$ touch '\12.txt'
包含斜槓的特殊情形
除非你的文件系統有問題,不然你不能建立名字包含斜槓的文件。沒辦法轉義斜槓。

因此若是你能建立相似 ‘/12.txt’ 或者 ‘b/c.txt’ 這樣的文件,那要麼你的文件系統有問題,或者支持 Unicode,這樣你能夠建立包含斜槓的文件。只是這樣並非真的斜槓,而是一個看起來像斜槓的 Unicode 字符。

文件名包含問號 (?)
用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改)

$ touch '?12.txt'
文件名包含點 (.)
在 Linux 裏以點 (.) 開頭的文件很是特別,被稱爲點文件。它們一般是隱藏的配置文件或系統文件。你須要使用 ls 命令的 ‘-a‘ 或 ‘-A‘ 開關來查看這種文件。

建立,編輯,重命名和刪除這種文件很直接。

$ touch .12.txt
注意:在 Linux 裏你可能碰到名字包含許多點 (.) 的文件。不像其餘操做系統,文件名裏的點並不意味着分隔名字和擴展後綴。你能夠建立名字包含多個點的文件:

$ touch 1.2.3.4.5.6.7.8.9.10.txt
檢查一下:

$ ls -l

total 0
-rw-r--r-- 1 avi avi 0 Jun 8 14:32 1.2.3.4.5.6.7.8.9.10.txt
文件名包含逗號 (,)
你能夠在文件名中使用逗號,能夠有任意多個而不用特殊對待。就像平時普通名字文件那樣處理。

$ touch ,12.txt
或者
$ touch ,12,.txt
文件名包含冒號 (:)
用單引號括起來或使用反斜槓轉義。(LCTT 譯註:此處原文有誤,已修改)

$ touch ':12.txt'
或者
$ touch ':12:.txt'
文件名包含引號(單引號和雙引號)
要在文件名裏使用引號,咱們須要使用交替規則。例如,若是你須要在文件名裏使用單引號,那就用雙引號把文件名括起來。而若是你須要在文件名裏使用雙引號,那就用單引號把文件名括起來。(LCTT 譯註:或者若是單引號和雙引號混雜的狀況,你也能夠用反斜槓轉義。)

$ touch "15'.txt"

以及

$ touch '15".txt'
文件名包含波浪號 (~)
Linux 下一些像 emacs 這樣的文本編輯器在編輯文件的時候會建立備份文件。這個備份文件的名字是在原文件名後面附加一個波浪號。你能夠在文件名任意位置使用波浪號,例如:

$ touch ~1a.txt
或者
$touch 2b~.txt
文件名包含空格
建立名字的字符/單詞之間包含空格的文件,好比 「hi my name is avishek.txt」。

最好不要在文件名裏使用空格,若是你必需要分隔可讀的名字,可使用下劃線或橫槓。不過,你仍是須要建立這樣的文件的話,你能夠用反斜槓來轉義下一個字符。要建立上面名字的文件能夠這樣作。

$ touch hi\ my\ name\ is\ avishek.txt

hi my name is avishek.txt
我已經嘗試覆蓋你可能碰到的全部狀況。上面大多數測試都在 BASH Shell 裏完成,可能在其餘 shell 下會有差別。

 

 

 

 

well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ ls
Client.php  Exception.php  Function.Business.php  Interface.php  Mock  Mock.php  Model  Model.php  Samples  Samples - Copy  Show
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ ll
total 112
drwxr-xr-x 7 root root  4096 May  4 19:47 ./
drwxr-xr-x 3 root root  4096 May  4 19:45 ../
-rwxrwxrwx 1 root root 36520 Apr 10 12:03 Client.php*
-rwxrwxrwx 1 root root  5033 Mar  2 12:41 Exception.php*
-rwxrwxrwx 1 root root  3542 Apr 24 16:24 Function.Business.php*
-rwxrwxrwx 1 root root  4708 Mar  2 12:41 Interface.php*
drwxrwxrwx 2 root root  4096 May  4 19:47 Mock/
-rwxrwxrwx 1 root root  6437 Mar  2 12:41 Mock.php*
drwxrwxrwx 2 root root  4096 May  4 19:47 Model/
-rwxrwxrwx 1 root root 17734 Mar  2 12:41 Model.php*
drwxrwxrwx 2 root root  4096 May  4 19:47 Samples/
drwxrwxrwx 3 root root  4096 May  4 15:30 Samples - Copy/
drwxrwxrwx 2 root root  4096 Apr 10 09:51 Show/
well@well:/home/etc/project/apilinux/MarketplaceWebServiceOrders$ 

 

 

 

 



sudo apt-get install foremost

w

 

 

debugfs:  ?
Available debugfs requests:

show_debugfs_params, params
                         Show debugfs parameters
open_filesys, open       Open a filesystem
close_filesys, close     Close the filesystem
freefrag, e2freefrag     Report free space fragmentation
feature, features        Set/print superblock features
dirty_filesys, dirty     Mark the filesystem as dirty
init_filesys             Initialize a filesystem (DESTROYS DATA)
show_super_stats, stats  Show superblock statistics
ncheck                   Do inode->name translation
icheck                   Do block->inode translation
change_root_directory, chroot
                         Change root directory
change_working_directory, cd
                         Change working directory
list_directory, ls       List directory
show_inode_info, stat    Show inode information 
dump_extents, extents, ex
                         Dump extents information 
blocks                   Dump blocks used by an inode 
filefrag                 Report fragmentation information for an inode
link, ln                 Create directory link
unlink                   Delete a directory link
mkdir                    Create a directory
rmdir                    Remove a directory
rm                       Remove a file (unlink and kill_file, if appropriate)
kill_file                Deallocate an inode and its blocks
clri                     Clear an inode's contents
freei                    Clear an inode's in-use flag
seti                     Set an inode's in-use flag
testi                    Test an inode's in-use flag
freeb                    Clear a block's in-use flag
setb                     Set a block's in-use flag
testb                    Test a block's in-use flag
modify_inode, mi         Modify an inode by structure
find_free_block, ffb     Find free block(s)
find_free_inode, ffi     Find free inode(s)
print_working_directory, pwd
                         Print current working directory
expand_dir, expand       Expand directory
mknod                    Create a special file
list_deleted_inodes, lsdel
                         List deleted inodes
undelete, undel          Undelete file
write                    Copy a file from your native filesystem
dump_inode, dump         Dump an inode out to a file
cat                      Dump an inode out to stdout
lcd                      Change the current directory on your native filesystem
rdump                    Recursively dump a directory to the native filesystem
set_super_value, ssv     Set superblock value
set_inode_field, sif     Set inode field
set_block_group, set_bg  Set block group descriptor field
logdump                  Dump the contents of the journal
htree_dump, htree        Dump a hash-indexed directory
dx_hash, hash            Calculate the directory hash of a filename
dirsearch                Search a directory for a particular filename
bmap                     Calculate the logical->physical block mapping for an inode
punch, truncate          Punch (or truncate) blocks from an inode by deallocating them
symlink                  Create a symbolic link
imap                     Calculate the location of an inode
dump_unused              Dump unused blocks
set_current_time         Set current time to use when setting filesystem fields
supported_features       Print features supported by this version of e2fsprogs
dump_mmp                 Dump MMP information
set_mmp_value, smmp      Set MMP value
extent_open, eo          Open inode for extent manipulation
zap_block, zap           Zap block: fill with 0, pattern, flip bits etc.
block_dump, bd           Dump contents of a block
help                     Display info on command or topic.
list_requests, lr, ?     List available commands.
quit, q                  Leave the subsystem.
debugfs:  
debugfs:  
debugfs:  
debugfs:  
debugfs:  q

 

 

 

linux 刪除文件和目錄與恢復詳解-linux-操做系統-壹聚教程網http://www.111cn.net/sys/linux/47629.htm

相關文章
相關標籤/搜索