find查找特殊文件

   

当在系统中看到这些很二的文件时怎么去删除、重命名;如下


    使用"ls"不跟选项显示到的结果

[root@Perthon tmp]# ls
^&*(  !@#$%^  *  *   document mysql  mydocument   myprogram


    使用"ls -l"显示到的结果

[root@Perthon tmp]# ls -l  看到这些文件名时怎样去删除和重命名 
total 20
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 ^&*(
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
-rw-r--r--. 1 root root    0 Jan 12 14:07 mydocument 
drwxr-xr-x. 2 root root 4096 Jan 12 14:06 myprogram


    使用rm尝试删除文件,结果看到并不能删除文件,更别说还有特殊字符了

[root@Perthon tmp]# rm -rf mydocument
[root@Perthon tmp]# ls -l
total 20
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 ^&*(
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
-rw-r--r--. 1 root root    0 Jan 12 14:07 mydocument 
drwxr-xr-x. 2 root root 4096 Jan 12 14:06 myprogram 
[root@Perthon tmp]# rm -rf myprogram
[root@Perthon tmp]# ls -l
total 20
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 ^&*(
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
-rw-r--r--. 1 root root    0 Jan 12 14:07 mydocument 
drwxr-xr-x. 2 root root 4096 Jan 12 14:06 myprogram

    

    这里主要是说:find查找特殊文件并执行删除(rm)、重命名(mv),当然find还有许多选项查找功能,其实从上面的所述的可以看出使用"rm -rf mydocument" 或者 "rm -rf myprogram"都没有指定到文件的唯一能识别的文件名,因此命令可执行,但并不能完成我们的需求,

    当然出来特殊符号的文件其他文件看来跟日常创建的文件没有任何区别,这些文件在创建时后面都分别跟了转义"\"加“空白"字符,如果在了解文件怎么创建的当然也可以删除,

 如以上的删除命令 "rm -rf mydocument\ "和 "rm -rf myprogram\ "即可删除,但是我们怎么查看到这些文件加了转义符的呢?呵呵!这些文件是我创建的,我当然知道是怎么回事,那么如果在不知道的情况下如和去删除这些文件。


    当然了显示文件还有一个叫 "ls -i"表示显示文件索引节点号,这个显示将是文件的唯一编号,当然也有叫"i节点"。认识就行不做强制区分


    使用“ls -i"显示到的结果,可以查看到每个文件或目录前都有一个索引号(inode)


[root@Perthon tmp]# ls -i
    14 ^&*(        11 *   128003 document mysql  128002 myprogram 
    15 !@#$%^      12 *       13 mydocument


    以上这些文件我们无法唯一标识文件名的本身,那么我们可以根据索引号来进行操作这些文件,那这里就得使用到find 选项中的 -inum 配合进行操作

    

find  [option] [ARG];这是find使用格式具体说明可查询http://man.linuxde.net/find 或其他文档
rm 命令:

[root@Perthon tmp]# find . -inum 13 -exec rm -rf {} \;   删除"mydocument"文本文件  
root@Perthon tmp]# ls -l
total 20
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 ^&*(
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
drwxr-xr-x. 2 root root 4096 Jan 12 14:06 myprogram 

[root@Perthon tmp]# find . -inum 128002 -exec rm -rf {} \;  删除"myprogram"目录文件
find: `./myprogram ': No such file or directory 报错信息此处目前可忽略,但是确实删除了
[root@Perthon tmp]# ls -l
total 16
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 ^&*(
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql

mv命令:
[root@Perthon tmp]# find -inum 14 -exec mv {} noderlinux \;  重命名 {}的值 
find: `./^&*(': No such file or directory 并且目录文件同样会报错信息
[root@Perthon tmp]# ls -l
total 16
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 !@#$%^
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 noderlinux

[root@Perthon tmp]# find -inum 15 -exec mv {} leaderlinux \;
find: `./!@#$%^': No such file or directory 并且目录文件同样会报错信息
[root@Perthon tmp]# ls -l
total 16
-rw-r--r--. 1 root root    0 Jan 12 14:04 *
drwxr-xr-x. 2 root root 4096 Jan 12 14:05 * 
drwxr-xr-x. 2 root root 4096 Jan 12 14:07 document mysql
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 leaderlinux
drwxr-xr-x. 2 root root 4096 Jan 12 14:09 noderlinux

    其他使用同理

你可能感兴趣的:(find,mv,rm)