【问题标题】:HDFS dfs -ls path/filenameHDFS dfs -ls 路径/文件名
【发布时间】:2025-12-29 11:40:06
【问题描述】:

我已将几个文件复制到该路径。但是当我尝试运行命令 hdfs dfs -ls path/filename 然后它返回没有找到文件。

hdfs dfs -ls 直到目录有效,但是当我使用文件名时,它返回未找到文件。对于其中一个文件,我使用 ambari 复制并粘贴了文件名。然后文件开始使用 hdfs dfs -ls path/filename 返回。

是什么导致了这个问题?

【问题讨论】:

    标签: hdfs


    【解决方案1】:

    因为当您执行HDFS dfs -ls path/filename 时,您对hdfs 说的是show me all the files that are in the directory,如果结束路径是一个文件,当然,您没有列出任何内容。你必须指向一个目录而不是一个文件。

    【讨论】:

    • 谢谢肯里。让我举例说明。 hdfs dfs -ls test/test2/test3/test.psv 它返回未找到文件。甚至认为test.psv存在下直接test 3.通过ambari,我复制了test.psv的文件名并粘贴到同一个文件中。然后上面开始识别文件。所以基本上我通过再次重命名文件来找到不同的文件名或路径。然后文件被识别
    • 好的,但是您是否将文件更改为另一个文件?如果你这样做了,我的结果答案是一样的,ls 只是列出目录。您可以尝试的另一个命令是hdfs dfs -ls -r,它将向您显示一个列出的递归目录。
    【解决方案2】:

    @saravanan 如果文件仅在使用 ambari 后显示,这似乎是一个权限问题。确保正确拥有文件以确认命令。 ls 命令将列出每个文档的文件和文件夹。

    这里是 ls 命令的完整文档:

    [root@hdp ~]# hdfs dfs -help ls
    -ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [-e] [<path> ...] :
      List the contents that match the specified file pattern. If path is not
      specified, the contents of /user/<currentUser> will be listed. For a directory a
      list of its direct children is returned (unless -d option is specified).
    
      Directory entries are of the form:
        permissions - userId groupId sizeOfDirectory(in bytes)
      modificationDate(yyyy-MM-dd HH:mm) directoryName
    
      and file entries are of the form:
        permissions numberOfReplicas userId groupId sizeOfFile(in bytes)
      modificationDate(yyyy-MM-dd HH:mm) fileName
    
        -C  Display the paths of files and directories only.
        -d  Directories are listed as plain files.
        -h  Formats the sizes of files in a human-readable fashion
            rather than a number of bytes.
        -q  Print ? instead of non-printable characters.
        -R  Recursively list the contents of directories.
        -t  Sort files by modification time (most recent first).
        -S  Sort files by size.
        -r  Reverse the order of the sort.
        -u  Use time of last access instead of modification for
            display and sorting.
        -e  Display the erasure coding policy of files and directories.
    

    【讨论】: