HDFS dfs指令

appendToFile
Usage: hdfs dfs -appendToFile <localsrc> ... <dst>
追加一个或者多个文件到hdfs制定文件中.也可以从命令行读取输入.
· hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile

cat
Usage: hdfs dfs -cat URI [URI ...]
查看内容.
Example:
· hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2

Chgrp【change group】
Usage: hdfs dfs -chgrp [-R] GROUP URI [URI ...]
修改所属组.

chmod
Usage: hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]
修改指定文件的权限.

chown
Usage: hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]
修改所有者.

copyFromLocal
Usage: hdfs dfs -copyFromLocal <localsrc> URI
与put指令类似,
Similar to put command, except that the source is restricted to a local file reference.

copyToLocal
Usage: hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst>

count
Usage: hdfs dfs -count [-q] [-h] <paths>
列出文件夹数量、文件数量、内容大小. The output columns with -count are: DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME

The output columns with -count -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME

The -h option shows sizes in human readable format.

Example:
· hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
· hdfs dfs -count -q hdfs://nn1.example.com/file1
· hdfs dfs -count -q -h hdfs://nn1.example.com/file1

cp
Usage: hdfs dfs -cp [-f] [-p | -p[topax]] URI [URI ...] <dest>
复制文件(夹),可以覆盖,可以保留原有权限信息

Options:
· The -f option will overwrite the destination if it already exists.
· The -p option will preserve file attributes [topx] (timestamps, ownership, permission, ACL, XAttr). If -p is specified with no arg, then preserves timestamps, ownership, permission. If -pa is specified, then preserves permission also because ACL is a super-set of permission. Determination of whether raw namespace extended attributes are preserved is independent of the -p flag.

Example:
· hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2
· hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir

du
Usage: hdfs dfs -du [-s] [-h] URI [URI ...]
显示文件(夹)大小.

Options:
· The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual files.
· The -h option will format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)

Example:
· hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1

dus
Usage: hdfs dfs -dus <args>
显示文件长度概况

Note: This command is deprecated. Instead use hdfs dfs -du -s.

expunge
Usage: hdfs dfs -expunge
清空回收站.

get
Usage: hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst>
在HDFS中下载文件到本地

Copy files to the local file system. Files that fail the CRC check may be copied with the -ignorecrc option. Files and CRCs may be copied using the -crc option.

Example:
· hdfs dfs -get /user/hadoop/file localfile
· hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile

getfacl
Usage: hdfs dfs -getfacl [-R] <path>
显示权限信息.
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

getfattr
Usage: hdfs dfs -getfattr [-R] -n name | -d [-e en] <path>
Displays the extended attribute names and values (if any) for a file or directory.

Options:
· -R: Recursively list the attributes for all files and directories.
· -n name: Dump the named extended attribute value.
· -d: Dump all extended attribute values associated with pathname.
· -e encoding: Encode values after retrieving them. Valid encodings are "text", "hex", and "base64". Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.

· path: The file or directory.

Examples:
· hdfs dfs -getfattr -d /file
· hdfs dfs -getfattr -R -n user.myAttr /dir

getmerge
Usage: hdfs dfs -getmerge <src> <localdst> [addnl]
合并.

ls
Usage: hdfs dfs -ls [-R] <args>

Options:
· The -R option will return stat recursively through the directory structure.
For a file returns stat on the file with the following format:

permissions number_of_replicas userid groupid filesize modification_date modification_time filename
For a directory it returns list of its direct children as in Unix. A directory is listed as:
permissions userid groupid modification_date modification_time dirname

Example:
· hdfs dfs -ls /user/hadoop/file1

lsr
Usage: hdfs dfs -lsr <args>
Recursive version of ls.
Note: This command is deprecated. Instead use hdfs dfs -ls -R

mkdir
Usage: hdfs dfs -mkdir [-p] <paths>
Takes path uri's as argument and creates directories.

Options:
· The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.

Example:
· hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
· hdfs dfs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir

moveFromLocal
Usage: hdfs dfs -moveFromLocal <localsrc> <dst>
上传本地指定文件到目录
Similar to put command, except that the source localsrc is deleted after it's copied.

moveToLocal
Usage: hdfs dfs -moveToLocal [-crc] <src> <dst>
Displays a "Not implemented yet" message.

mv
Usage: hdfs dfs -mv URI [URI ...] <dest>
Moves files from source to destination. This command allows multiple sources as well in which case the destination needs to be a directory. Moving files across file systems is not permitted.

Example:
· hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2
· hdfs dfs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1

put
Usage: hdfs dfs -put <localsrc> ... <dst>
上传本地文件到HDFS系统
Copy single src, or multiple srcs from local file system to the destination file system. Also reads input from stdin and writes to destination file system.

· hdfs dfs -put localfile /user/hadoop/hadoopfile
· hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir
· hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile
· hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.

rm
Usage: hdfs dfs -rm [-f] [-r|-R] [-skipTrash] URI [URI ...]
删除文件
Options:
· The -f option will not display a diagnostic message or modify the exit status to reflect an error if the file does not exist.

· The -R option deletes the directory and any content under it recursively.
· The -r option is equivalent to -R.
· The -skipTrash option will bypass trash, if enabled, and delete the specified file(s) immediately. This can be useful when it is necessary to delete files from an over-quota directory.

Example:
· hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir

rmr
Usage: hdfs dfs -rmr [-skipTrash] URI [URI ...]
删除文件
Note: This command is deprecated. Instead use hdfs dfs -rm -r

setfacl
Usage: hdfs dfs -setfacl [-R] [-b|-k -m|-x <acl_spec> <path>]|[--set <acl_spec> <path>]
Sets Access Control Lists (ACLs) of files and directories.
设置权限相关指令
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>
Sets an extended attribute name and value for a file or directory.
设置文件或目录相关属性操作

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>
Changes the replication factor of a file. If path is a directory then the command recursively changes the replication factor of all files under the directory tree rooted at 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
Displays last kilobyte of the file to stdout.

Options:
· The -f option will output appended data as the file grows, as in Unix.
Example:
· hdfs dfs -tail pathname

test
Usage: hdfs dfs -test -[ezd] URI

Options:
· The -e option will check to see if the file exists, returning 0 if true.
· The -z option will check to see if the file is zero length, returning 0 if true.
· The -d option will check to see if the path is directory, returning 0 if true.

Example:
· hdfs dfs -test -e filename

text
Usage: hdfs dfs -text <src>

Takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream.

touchz
Usage: hdfs dfs -touchz URI [URI ...]
在HDFS文件系统中创建文件

Example:
· hdfs dfs -touchz pathname

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,001评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,210评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,874评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,001评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,022评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,005评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,929评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,742评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,193评论 1 309
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,427评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,583评论 1 346
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,305评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,911评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,564评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,731评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,581评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,478评论 2 352

推荐阅读更多精彩内容