How to update the last modified timestamp of a file in HDFS?

Sometimes, we come across a situation where we may need to update the last modified time of a file in HDFS. We can achieve it using Hadoop FileSystem API in Java.

Step 1:

Create a simple maven project in Eclipse.

 

Step 2:

Update the below dependencies in pom.xml file.

 

Step 3:

Create a java class “UpdateHDFSFileModifiedTime” in the package “org.sample“.

 

Step 4:

Please do “Maven Install” to create the jar as below.

 

Step 5:

In Cloudera VM or UNIX machine where Hadoop and HDFS are installed, open a terminal and execute the below command:

 

This command will update the last modified time of the provided HDFS file to with the date time older than <No of Days> specified.

 

Eg:

 

Please comment below in case of any queries.

Leave a Reply

Your email address will not be published. Required fields are marked *