hdfs use operation command

  1. -cat
使用方法:hadoop fs -cat URI [URI …]

将路径指定文件的内容输出到stdout

实例:hadoop fs -cat file:///file3 /user/hadoop/file4
  1. -chgrp
使用方法:hadoop fs -chgrp [-R] GROUP URI [URI …]

改变文件所属的组。使用-R将使改变在目录结构下递归进行。命令的使用者必须是文件的所有者或者超级用户
  1. -chmod
使用方法:hadoop fs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI …]

改变文件的权限。使用-R将使改变在目录结构下递归进行。命令的使用者必须是文件的所有者或者超级用户。
  1. -chown
使用方法:hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]

改变文件的拥有者。使用-R将使改变在目录结构下递归进行。命令的使用者必须是超级用户
  1. -copyFromLocal
使用方法:hadoop fs -copyFromLocal <localsrc> URI

除了限定源路径是一个本地文件外,和put命令相似。
  1. -copyToLocal
使用方法:hadoop fs -copyToLocal [-ignorecrc] [-crc] URI <localdst>

除了限定目标路径是一个本地文件外,和get命令类似。
  1. -cp
使用方法:hadoop fs -cp URI [URI …] <dest>

将文件从源路径复制到目标路径。这个命令允许有多个源路径,此时目标路径必须是一个目录。 


hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir
  1. -from
使用方法:hadoop fs -du URI [URI …]

显示目录中所有文件的大小,或者当只指定一个文件时,显示此文件的大小。
示例:
hadoop fs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://host:port/user/hadoop/dir1 
  1. -So
使用方法:hadoop fs -dus <args>

显示文件的大小。
  1. -expunge
使用方法:hadoop fs -expunge

清空回收站
  1. -get
使用方法:hadoop fs -get [-ignorecrc] [-crc] <src> <localdst> 
复制文件到本地文件系统。可用-ignorecrc选项复制CRC校验失败的文件。使用-crc选项复制文件以及CRC信息。


hadoop fs -get hdfs://host:port/user/hadoop/file localfile
  1. -getmerge
使用方法:hadoop fs -getmerge <src> <localdst> [addnl]

接受一个源目录和一个目标文件作为输入,并且将源目录中所有的文件连接成本地目标文件。addnl是可选的,用于指定在每个文件结尾添加一个换行符。
  1. -ls
使用方法:hadoop fs -ls <args>

如果是文件,则按照如下格式返回文件信息:
文件名 <副本数> 文件大小 修改日期 修改时间 权限 用户ID 组ID 
如果是目录,则返回它直接子文件的一个列表,就像在Unix中一样。目录返回列表的信息如下:
目录名 <dir> 修改日期 修改时间 权限 用户ID 组ID 

hadoop fs -ls /user/hadoop/file1 /user/hadoop/file2 hdfs://host:port/user/hadoop/dir1 /nonexistentfile 
  1. -lsr
使用方法:hadoop fs -lsr <args> 
ls命令的递归版本
  1. -mkdir
使用方法:hadoop fs -mkdir <paths> 
接受路径指定的uri作为参数,创建这些目录。其行为类似于Unix的mkdir -p,它会创建路径中的各级父目录。


hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2


一级一级的建
  1. -movefromLocal
使用方法:dfs -moveFromLocal <src> <dst>
  1. -mv
使用方法:hadoop fs -mv URI [URI …] <dest>

将文件从源路径移动到目标路径。这个命令允许有多个源路径,此时目标路径必须是一个目录。不允许在不同的文件系统间移动文件。

hadoop fs -mv /user/hadoop/file1 /user/hadoop/file2
  1. -put
使用方法:hadoop fs -put <localsrc> ... <dst>

从本地文件系统中复制单个或多个源路径到目标文件系统。也支持从标准输入中读取输入写入目标文件系统。

hadoop fs -put localfile /user/hadoop/hadoopfile
  1. -rm
使用方法:hadoop fs -rm URI [URI …]

删除指定的文件。只删除非空目录和文件。请参考rmr命令了解递归删除。

-rmr 递归调用
  1. -setrep
使用方法:hadoop fs -setrep [-R] <path>

改变一个文件的副本系数。-R选项用于递归改变目录下所有文件的副本系数。


hadoop fs -setrep -w 3 -R /user/hadoop/dir1
  1. -stat
使用方法:hadoop fs -stat URI [URI …]

返回指定路径的统计信息。
  1. -tail
使用方法:hadoop fs -tail [-f] URI

将文件尾部1K字节的内容输出到stdout。支持-f选项,行为和Unix中一致
  1. -test
使用方法:hadoop fs -test -[ezd] URI

选项:
-e 检查文件是否存在。如果存在则返回0。
-z 检查文件是否是0字节。如果是则返回0。 
-d 如果路径是个目录,则返回1,否则返回0。

hadoop fs -test -e filename
  1. -text
使用方法:hadoop fs -text <src> 
将源文件输出为文本格式。允许的格式是zip和TextRecordInputStream。
  1. -touchz
使用方法:hadoop fs -touchz URI [URI …] 
创建一个0字节的空文件。

hadoop -touchz pathname
  • hdfs undelete files
hdfs dfs -ls /user/用户/.Trash/Current下找文件
然后直接-mv
  • Randomly returns sample data for the specified number of rows
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | shuf -n 5
  • Returns sample data for the first few rows
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | head -100
  • Returns the last few rows of sample data
hadoop fs -cat /test/gonganbu/scene_analysis_suggestion/* | tail -5
  • View the number of lines of text
hadoop fs -cat hdfs://172.16.0.226:8020/test/sys_dict/sysdict_case_type.csv |wc -l
  • Check file size
hadoop fs -du -h hdfs://172.16.0.226:8020/test/sys_dict/*hadoop fs -du hdfs://172.16.0.226:8020/test/sys_dict/*
  • View the number of files
hadoop fs -count hdfs://172.16.0.226:8020/test/sys_dict/*

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324397687&siteId=291194637