转自
在core-default.xml中
<property> <name>fs.trash.interval</name> <value>0</value> <description>Number of minutes between trash checkpoints. If zero, the trash feature is disabled. </description></property>也就是如果在core-site.xml中设置了 fs.trash.interval ,则会启用trash功能<property><name>fs.trash.interval</name>
<value>60</value>
<description>Number of minutes between trash checkpoints. If zero, the trash feature is disabled. </description>
</property>
譬如如上所示,设置间隔时间为1小时.为了测试我们设置该参数为3分钟建立文件:[hadoop@HMaster conf]$ hadoop fs -touchz test/1.txt[hadoop@HMaster conf]$ hadoop fs -touchz test/2.txt
[hadoop@HMaster conf]$ hadoop fs -ls test/*
-rw-r--r-- 1 hadoop supergroup 0 2012-09-08 23:33 /user/hadoop/test/1.txt
-rw-r--r-- 1 hadoop supergroup 0 2012-09-08 23:33 /user/hadoop/test/2.txt
删除文件:[hadoop@HMaster conf]$ hadoop fs -rmr test/1.txt
Moved to trash: hdfs://localhost:9000/user/hadoop/test/1.txt
[hadoop@HMaster conf]$ hadoop fs -ls test
/*Found 1 items-rw-r--r-- 1 hadoop supergroup 0 2012-09-08 23:33 /user/hadoop/test/2.txt一旦删除,将会建立.Trash目录(如果以前不存在的话)然后查询[hadoop@HMaster conf]$ hadoop fs -ls .Trash/Current/user
/*Found 1 itemsdrwx------ - hadoop supergroup 0 2012-09-08 23:33 /user/hadoop/.Trash/Current/user/hadoop/test1分钟后[hadoop@HMaster conf]$ hadoop fs -ls .Trash/1209082336/user/hadoop/test
Found 1 items-rw-r--r-- 1 hadoop supergroup 0 2012-09-08 23:33 /user/hadoop/.Trash/1209082336/user/hadoop/test/1.txt3分钟之后: [hadoop@HMaster conf]$ hadoop fs -ls .Trash/文件已经被删除在此期间可以使用hadoop fs -cp/mv等命令把文件或文件夹恢复回去