File 从UNIX更改HDFS文件创建日期
我希望在UNIX中使用类似于touch的命令来更改文件的最后修改日期。 触摸屏-d 20101 hdfs的等效touchz命令不支持此操作。 hadoop fs-touchz-d 20101File 从UNIX更改HDFS文件创建日期,file,unix,hadoop,hdfs,File,Unix,Hadoop,Hdfs,我希望在UNIX中使用类似于touch的命令来更改文件的最后修改日期。 触摸屏-d 20101 hdfs的等效touchz命令不支持此操作。 hadoop fs-touchz-d 20101 在Hadoop中,是否有任何方法可以使用UNIX或其他方式更改文件的最后修改日期?据我所知,没有shell命令可以做到这一点 但是可以通过Java 公共无效设置时间(路径p, 很长时间, (长时间) 抛出IOException 设置文件的访问时间 参数: p-路径 mtime-设置此文件的修改时间。自197
在Hadoop中,是否有任何方法可以使用UNIX或其他方式更改文件的最后修改日期?据我所知,没有shell命令可以做到这一点 但是可以通过
Java
公共无效设置时间(路径p,
很长时间,
(长时间)
抛出IOException
设置文件的访问时间
参数:
p-路径
mtime-设置此文件的修改时间。自1970年1月1日以来的毫秒数。值-1表示此调用
不应设置修改时间。
atime-设置此文件的访问时间。自1970年1月1日以来的毫秒数。值-1表示此调用
不应设置访问时间
如果您不想按照@SCouto的建议编写java代码,您可以通过一个简单的解决方法来实现,下面是我对如何实现的解释
#Changing the file timestamp to 201708210100 in local unix file system
[root@quickstart TestFolder]# touch -t 201708210100 SomeTestFile.txt
[root@quickstart TestFolder]# ls -lh
total 0
-rw-r--r-- 1 root root 0 Aug 21 01:00 SomeTestFile.txt
#when copying the file to hdfs i'm using -p option which preserves the file timestamp
[root@quickstart TestFolder]# hdfs dfs -copyFromLocal -p SomeTestFile.txt /Temp
#After copying the file if you look at the below TS its reflected the same way in as in local
[root@quickstart TestFolder]# hdfs dfs -ls /Temp/SomeTestFile.txt
-rw-r--r-- 1 root root 0 2017-08-21 01:00 /Temp/SomeTestFile.txt
p.S-更改本地文件系统时间,并在将文件复制到hdfs时使用-p
,这将在hdfs中保留并反映相同的时间
如果您关心创建一个新文件并在每次更新时更新它,您可以使用-f
执行以下操作,从而覆盖/强制更新该文件
#HDFS FILE SomeTestFile.txt
hdfs dfs -ls /Temp/SomeTestFile.txt
#To change the file TS for SomeTestFile.txt #Get it to local
hdfs dfs -get /Temp/SomeTestFile.txt /SomeFolderInLinux/
#Change the time in local with touch
touch -t 201701010100 /SomeFolderInLinux/SomeTestFile.txt
#Here is the main part of preserving the time and overwriting the file in hdfs
hdfs dfs -copyFromLocal -p -f /SomeFolderInLinux/SomeTestFile.txt /Temp/
Hadoop确实提供了这个功能 通用命令行语法为: 命令[genericOptions][commandOptions]
用法:hadoop fs[通用选项]-touch[-a][m][t TIMESTAMP][c]…您使用的是什么版本的hadoop?因为在我的版本中没有触摸命令。如上所述,有一个touchz命令,但它不满足要求。