网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > Linux
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 153.99.37.70
Old 2015-10-23, 01:36 PM
Kenova Kenova is offline
初级会员
 
Join Date: 2010-12-27
Posts: 1
Kenova 现在声名狼藉
Default CentOS下删除或重命名乱码文件

当文件名为乱码的时候,无法通过键盘输入文件名,所以在终端下就不能直接利用rm,mv等命令管理文件了。当文件名为乱码的时候,无法通过键盘输入文件名,所以在终端下就不能直接利用rm,mv等命令管理文件了。

但是每个文件都有一个i节点号,可以通过i节点号来管理文件。首先,要取得文件的i节点号。这个可以通过ls命令的-i选项获得得。

一、删除

第一步:获取文件的id号

ls -li

第二步:执行删除

find ./ -inum 32983551 -exec rm {} \;

二、重命名

find ./ -inum 32983542 -exec mv {} test.php \;

当文件名为乱码的时候,无法通过键盘输入文件名,所以在终端下就不能直接利用rm,mv等命令管理文件了。

但是每个文件都有一个i节点号,可以通过i节点号来管理文件。首先,要取得文件的i节点号。这个可以通过ls命令的-i选项获得得。

-bash-3.00$ ls -i
41697812 a 32983551 di 32983554 ethnet.c 32983543 hard_link
32983542 de.c 32983544 ethnet 32983541 ethnet.h 32983543 kstat

每个文件名前面的数字就是文件的i节点号。有了文件的i节点号,我们就可以利用find命令的-inum选项配合
常用的文件管理命令进行文件管理了。例如,如果要删除di文件,命令如下:
-bash-3.00$ find . -inum 32983551 -exec rm {} \;
-bash-3.00$ ls
a de.c ethnet ethnet.c ethnet.h hard_link kstat

看di文件被删除了。因为这个例子是在unix-center的机子上运行的,暂时没有文件名为乱码的文件做为示例,
但是道理是一样的,不影响我们的理解。

要重命名一个文件,命令也很简单,如下:
-bash-3.00$ ls -i
32983542 de.c 32983554 ethnet.c 32983543 hard_link 32983545 kstat.c
32983544 ethnet 32983541 ethnet.h 32983543 kstat 32983681 sys_link
-bash-3.00$ find . -inum 32983542 -exec mv {} di.c \;
-bash-3.00$ ls -i
32983542 di.c 32983554 ethnet.c 32983543 hard_link 32983545 kstat.c
32983544 ethnet 32983541 ethnet.h 32983543 kstat 32983681 sys_link

看看,de.c文件被重命名为di.c了。特别要提一下的是,在find命令中的“{}”表示find命令找到的文件,在
-exec选项执行mv命令的时候,会利用按i节点号找到的文件名替换掉“{}”

Last edited by topvip : 2015-11-11 at 07:37 PM
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:45 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.