Hadoop Shell命令官网翻译

前提是你 提交于 2020-03-01 03:42:37


FS Shell

调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式。 所有的的FS shell命令使用URI路径作为参数。URI格式是scheme://authority/path。对HDFS文件系统,scheme是hdfs,对本地文件系统,scheme是file。其中scheme和authority参数都是可选的,如果未加指定,就会使用配置中指定的默认scheme。一个HDFS文件或目录比如/parent/child可以表示成hdfs://namenode:namenodeport/parent/child,或者更简单的/parent/child(假设你配置文件中的默认值是namenode:namenodeport)。大多数FS Shell命令的行为和对应的Unix Shell命令类似,不同之处会在下面介绍各命令使用详情时指出。出错信息会输出到stderr,其他信息输出到stdout

  • appendToFile
    • Usage: hdfs dfs -appendToFile <localsrc> ... <dst>
    • 将本地文件系统的单个文件或者多个文件追加到目标文件系统,支持stdin标准输入
    • hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile
    • hdfs dfs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile
    • hdfs dfs -appendToFile localfile hdfs://nn.example.com/hadoop/hadoopfile
    • hdfs dfs -appendToFile - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.
    • Exit Code:
      Returns 0 on success and 1 on error.
  • cat
    • 使用方法:hdfs dfs -cat URI [URI …]
    • 将路径指定文件的内容输出到stdout。
    • 示例:
      • hdfs dfs -cat hdfs://host1:port1/file1 hdfs://host2:port2/file2
      • hdfs dfs -cat file:///file3 /user/hadoop/file4
    • 返回值:成功返回0,失败返回-1。
  • chgrp
    • 使用方法:hdfs dfs -chgrp [-R] GROUP URI [URI …]
    • 改变文件所属的组。使用-R将使改变在目录结构下递归进行。命令的使用者必须是文件的所有者或者超级用户。更多的信息请参见HDFS权限用户指南
  • chmod
    • 使用方法:hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI …]
    • 改变文件的权限。使用-R将使改变在目录结构下递归进行。命令的使用者必须是文件的所有者或者超级用户。更多的信息请参见HDFS权限用户指南
  • chown
    • 使用方法:hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]
    • 改变文件的拥有者。使用-R将使改变在目录结构下递归进行。命令的使用者必须是超级用户。更多的信息请参见HDFS权限用户指南
  • copyFromLocal
    • Usage: hdfs dfs -copyFromLocal <localsrc> URI
    • 除了限定源路径是一个本地文件外,和put命令相似。
    • Options:     -f选项将覆盖目标如果目标已经存在。
  • copyToLocal
    • Usage: hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst>
    • 除了限定目标路径是一个本地文件外,和get命令类似。
  • count
    • Usage: hdfs dfs -count [-q] <paths>
    • 计算目录的数量,与指定文件模式匹配的路径的文件和字节。
    • 使用-count输出列是:DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME
    • 使用-count -q 输出列是:QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME
    • Example:    
    • Exit Code:Returns 0 on success and -1 on error.
  • cp
    • Usage: hdfs dfs -cp [-f] [-p | -p[topax]] URI [URI ...] <dest>
    • 将文件从源路径复制到目标路径。这个命令允许有多个源路径,此时目标路径必须是一个目录。
      • Options:-f选项将覆盖目标。
      • -p选项将保存的文件属性[ TOPX ](时间戳,所有权,许可,ACL,xattr)。如果-p不是特定的,然后保存时间戳,所有权,许可。如果PA是指定的,然后保留权限也因为ACL是一个允许超集合
    • Example:    
      • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2    
      • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir
    • Exit Code:Returns 0 on success and -1 on error.
  • du
    • Usage: hdfs dfs -du [-s] [-h] URI [URI ...]
    • 显示目录中所有文件的大小,或者当只指定一个文件时,显示此文件的大小。
    • Options:
      • -s选项将会在文件的长度显示总的概括,而不是单个文件。
      • - H选项将格式在“人类可读的“时尚大小文件(如64.0M代替67108864)
    • Example:     hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1
    • Exit Code: Returns 0 on success and -1 on error.
  • dus
    • Usage: hdfs dfs -dus <args>
    • 显示文件长度的概要。这是HDFS的DFS –du –s 的一个备用状态。
  • expunge
    • Usage: hdfs dfs -expunge
    • 清空回收站。请参考HDFS设计文档以获取更多关于回收站特性的信息。
  • get
    • Usage: hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst>
    • 复制文件到本地文件系统。可用-ignorecrc选项复制CRC校验失败的文件。使用-crc选项复制文件以及CRC信息。
    • Example:    
    • Exit Code:Returns 0 on success and -1 on error.
  • getfacl
    • Usage: hdfs dfs -getfacl [-R] <path>
    • 显示访问控制列表(ACL)的文件和目录。如果一个目录有一个默认的ACL,然后getfacl也显示默认的ACL。
    • Options:    
      • -R: List the ACLs of all files and directories  recursively.    
      • path: File or directory to list.
    • Examples:    
      • hdfs dfs -getfacl /file    
      • hdfs dfs -getfacl -R /dir
    • Exit Code:Returns 0 on success and non-zero on error.
  • getfattr
    • Usage: hdfs dfs -getfattr [-R] -n name | -d [-e en] <path>
    • 显示一个文件或者目录的扩展属性吗和值
    • Options:  
      •   -R: 递归列出    
      • -n 名称:自指定的扩展属性。    
      • -d 转储所有扩展属性值与路径    
      • -e 编码:编码值后,检索。有效的编码是“文本”,“hex”,和“Base64”。编码值为文本字符串括在双引号(“),编码值为十六进制和Base64的前缀分别为0x和0s    
      • path: 文件或者目录.
    • Examples:  
      • hdfs dfs -getfattr -d /file
      • hdfs dfs -getfattr -R -n user.myAttr /dir
    • Exit Code:Returns 0 on success and non-zero on error.
  • getmerge
    • Usage: hdfs dfs -getmerge <src> <localdst> [addnl]
    • 接受一个源目录和一个目标文件作为输入,并且将源目录中所有的文件连接成本地目标文件。addnl是可选的,用于指定在每个文件结尾添加一个换行符。
  • ls
    • Usage: hdfs dfs -ls <args>
    • 如果是文件,则按照如下格式返回文件信息:
    • 文件名 <副本数> 文件大小 修改日期 修改时间 权限 用户ID 组ID
    • 如果是目录,则返回它直接子文件的一个列表,就像在Unix中一样。
    • 目录返回列表的信息如下:
      • 目录名 <dir> 修改日期 修改时间 权限 用户ID 组ID
    • Exit Code:Returns 0 on success and -1 on error.
  • lsr
    • 使用方法:hadoop fs -lsr <args>
    • ls命令的递归版本。类似于Unix中的ls -R。
  • mkdir
    • Usage: hdfs dfs -mkdir [-p] <paths>
    • 接受路径指定的uri作为参数,创建这些目录。其行为类似于Unix的mkdir -p,它会创建路径中的各级父目录。
    • Options:-p选项的行为非常像UNIX mkdir -p,创建父目录路径。
  • moveFromLocal
    • Usage: hdfs dfs -moveFromLocal <localsrc> <dst>
    • 跟put类似的命令,除了源localsrc是在它的复制之后被删除掉。
  • moveToLocal
    • Usage: hdfs dfs -moveToLocal [-crc] <src> <dst>
    • Displays a "Not implemented yet" message.
  • mv
    • Usage: hdfs dfs -mv URI [URI ...] <dest>
    • 将文件从源路径移动到目标路径。这个命令允许有多个源路径,此时目标路径必须是一个目录。不允许在不同的文件系统间移动文件。
  • put
    • Usage: hdfs dfs -put <localsrc> ... <dst>
    • 从本地文件系统中复制单个或多个源路径到目标文件系统。也支持从标准输入中读取输入写入目标文件系统。
  • rm
    • Usage: hdfs dfs -rm [-skipTrash] URI [URI ...]
    • 删除指定参数的文件。只删除非空的目录和文件。If the -skipTrash option is specified, the trash, if enabled, will be bypassed and the specified file(s) deleted immediately. This can be useful when it is necessary to delete files from an over-quota directory.参考指rmr递归删除。
  • rmr
    • Usage: hdfs dfs -rmr [-skipTrash] URI [URI ...]
    • 删除的递归版本。If the -skipTrash option is specified, the trash, if enabled, will be bypassed and the specified file(s) deleted immediately. This can be useful when it is necessary to delete files from an over-quota directory.
  • setfacl
    • Usage: hdfs dfs -setfacl [-R] [-b|-k -m|-x <acl_spec> <path>]|[--set <acl_spec> <path>]
    • 设置文件和目录的访问控制列表(ACL)。
    • Options:
      • -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
      • -k: Remove the default ACL.
      • -R: Apply operations to all files and directories recursively.
      • -m: Modify ACL. New entries are added to the ACL, and existing entries are retained.
      • -x: Remove specified ACL entries. Other ACL entries are retained.
      • --set: Fully replace the ACL, discarding all existing entries. The acl_spec must include entries for user, group, and others for compatibility with permission bits.
      • acl_spec: Comma separated list of ACL entries.
      • path: File or directory to modify.
    • Examples:
      • hdfs dfs -setfacl -m user:hadoop:rw- /file
      • hdfs dfs -setfacl -x user:hadoop /file
      • hdfs dfs -setfacl -b /file
      • hdfs dfs -setfacl -k /dir
      • hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
      • hdfs dfs -setfacl -R -m user:hadoop:r-x /dir
      • hdfs dfs -setfacl -m default:user:hadoop:r-x /dir
  • setfattr
    • Usage: hdfs dfs -setfattr -n name [-v value] | -x name <path>
    • 设置文件或目录的一个扩展属性的名称和值。
    • Options:
      • -b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
      • -n name: The extended attribute name.
      • -v value: The extended attribute value. There are three different encoding methods for the value. If the argument is enclosed in double quotes, then the value is the string inside the quotes. If the argument is prefixed with 0x or 0X, then it is taken as a hexadecimal number. If the argument begins with 0s or 0S, then it is taken as a base64 encoding.
      • -x name: Remove the extended attribute.
      • path: The file or directory.
    • Examples:
      • hdfs dfs -setfattr -n user.myAttr -v myValue /file
      • hdfs dfs -setfattr -n user.noValue /file
      • hdfs dfs -setfattr -x user.myAttr /file
  • setrep
    • Usage: hdfs dfs -setrep [-R] [-w] <numReplicas> <path>
    • 改变文件的复制因子。如果path 是一个目录,那么命令递归改变此目录树路径下的所有文件的复制因子。
    • Options:
      • The -w flag requests that the command wait for the replication to complete. This can potentially take a very long time.
      • The -R flag is accepted for backwards compatibility. It has no effect.
    • Example:hdfs dfs -setrep -w 3 /user/hadoop/dir1
  • stat
    • Usage: hdfs dfs -stat URI [URI ...]
    • 返回指定路径的统计信息。
    • Example:hdfs dfs -stat path
  • tail
    • Usage: hdfs dfs -tail [-f] URI
    • 将文件尾部1K字节的内容输出到stdout。支持-f选项,行为和Unix中一致。
  • test
    • Usage: hdfs dfs -test -[ezd] URI
    • 选项:
      • -e 检查文件是否存在。如果存在则返回0。
      • -z 检查文件是否是0字节。如果是则返回0。
      • -d 如果路径是个目录,则返回1,否则返回0。
  • text
    • Usage: hdfs dfs -text <src>
    • 将源文件输出为文本格式。允许的格式是zip和TextRecordInputStream。
  • touchz
    • Usage: hdfs dfs -touchz URI [URI ...]
    • 创建一个0字节的空文件。
    • Example:
      • hadoop -touchz pathname






















易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!