简体   繁体   English

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

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

I do not know why I cannot move a file from one directory to another.我不知道为什么我不能将文件从一个目录移动到另一个目录。 I can view the content of the file but I cannot move the same file into another directory.我可以查看文件的内容,但不能将同一个文件移动到另一个目录中。

WORKS FINE:工作正常:

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

DOES NOT WORK:不起作用:

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

I got a No such file or directory error message.我收到No such file or directory错误消息。 What is wrong?怎么了? Please help.请帮忙。 Thank you!谢谢!

As we can read from here about the -put command:正如我们可以从这里读到的-put命令:

This command is used to copy files from the local file system to the HDFS filesystem .该命令用于将文件从本地文件系统复制到 HDFS 文件系统 This command is similar to –copyFromLocal command.此命令类似于 –copyFromLocal 命令。 This command will not work if the file already exists unless the –f flag is given to the command.如果文件已经存在,则此命令将不起作用,除非为该命令提供了 –f 标志。 This overwrites the destination if the file already exists before the copy如果文件在复制之前已经存在,这将覆盖目标

Which makes it clear why it doesn't work and throws the No such file or directory message.这清楚地说明了为什么它不起作用并抛出No such file or directory消息。 It's because it can't find any file with the name project-data.txt on your current directory of your local filesystem.这是因为它在本地文件系统的当前目录中找不到任何名为project-data.txt文件。

You plan on moving a file between directories inside the HDFS, so instead of using the -put parameter for moving, we can simply use the -mv parameter as we would in our local filesystem!您计划在 HDFS的目录之间移动文件,因此我们可以像在本地文件系统中一样简单地使用-mv参数,而不是使用-put参数进行移动!

Tested it out on my own HDFS as follows:在我自己的 HDFS 上进行了如下测试:

  1. Create the source and destination directories in HDFS在 HDFS 中创建源目录和目标目录

hadoop fs -mkdir source_dir dest_dir

  1. Create an empty (for the sake of the test) file under the source directory在源目录下创建一个空的(为了测试)文件

hadoop fs -touch source_dir/test.txt

  1. Move the empty file to the destination directory将空文件移动到目标目录

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

(Notice how the /user/username/ part of the path for the file and the destination directory is not needed, because HDFS is by default on this directory where you are working. You also should note that you have to write the full path of the destination with name of the file included .) (注意文件路径和目标目录的/user/username/部分是如何不需要的,因为 HDFS 默认位于您正在工作的这个目录中。您还应该注意,您必须写下包含文件名的目的地。)

You can see below with the HDFS browser that the empty text file has been moved to the destination directory:您可以在下面使用 HDFS 浏览器看到空文本文件已移动到目标目录: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM