Hadoop/HDFS: put 命令失败 - 没有这样的文件或目录

Hadoop/HDFS: put command fails - No such file or directory

我不知道为什么我不能将文件从一个目录移动到另一个目录。我可以查看文件的内容,但无法将同一个文件移动到另一个目录。

工作正常:

hadoop fs -cat /user/hadoopusr/project-data.txt

不工作:

hadoop fs -put /user/hadoopusr/project-data.txt /user/hadoopusr/Projects/MarketAnalysis

我收到一条 No such file or directory 错误消息。怎么了?请帮忙。谢谢!

我们可以从 here 中了解到 -put 命令:

This command is used to copy files from the local file system to the HDFS filesystem. This command is similar to –copyFromLocal command. This command will not work if the file already exists unless the –f flag is given to the command. This overwrites the destination if the file already exists before the copy

这清楚地说明了为什么它不起作用并抛出 No such file or directory 消息。这是因为它在本地文件系统的当前目录中找不到名称为 project-data.txt 的任何文件。

您计划在 HDFS 目录之间移动文件,因此我们可以简单地使用 -mv 参数就像我们在本地文件系统中一样!

在自己的HDFS上测试如下:

  1. 在 HDFS 中创建源目录和目标目录

hadoop fs -mkdir source_dir dest_dir

  1. 在源目录下创建一个空文件(为了测试)

hadoop fs -touch source_dir/test.txt

  1. 将空文件移动到目标目录

hadoop fs -mv source_dir/test.txt dest_dir/test.txt

(注意文件路径的 /user/username/ 部分和目标目录是不需要的,因为 HDFS 默认位于您工作的目录中。您还应该注意,您必须将目标的完整路径 写入包含的文件名 。)

在HDFS浏览器下可以看到空文本文件已经移动到目标目录: