HDFS dfs指令

appendToFile
Usage: hdfs dfs -appendToFile <localsrc> ... <dst>
追加一個(gè)或者多個(gè)文件到hdfs制定文件中.也可以從命令行讀取輸入.
· hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile

cat
Usage: hdfs dfs -cat URI [URI ...]
查看內(nèi)容.
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 ...]
修改指定文件的權(quán)限.

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>
列出文件夾數(shù)量拙毫、文件數(shù)量、內(nèi)容大小. 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>
復(fù)制文件(夾),可以覆蓋,可以保留原有權(quán)限信息

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>
顯示文件長(zhǎng)度概況

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>
顯示權(quán)限信息.
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系統(tǒng)
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.
設(shè)置權(quán)限相關(guān)指令
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.
設(shè)置文件或目錄相關(guān)屬性操作

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 ...]
返回當(dāng)前路徑的狀態(tài)信息

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文件系統(tǒng)中創(chuàng)建文件

Example:
· hdfs dfs -touchz pathname

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末矾策,一起剝皮案震驚了整個(gè)濱河市甲喝,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌雳旅,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,270評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件间聊,死亡現(xiàn)場(chǎng)離奇詭異攒盈,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)哎榴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門型豁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)僵蛛,“玉大人,你說(shuō)我怎么就攤上這事迎变〕湮荆” “怎么了?”我有些...
    開封第一講書人閱讀 165,630評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵衣形,是天一觀的道長(zhǎng)驼侠。 經(jīng)常有香客問我,道長(zhǎng)泵喘,這世上最難降的妖魔是什么泪电? 我笑而不...
    開封第一講書人閱讀 58,906評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮纪铺,結(jié)果婚禮上相速,老公的妹妹穿的比我還像新娘。我一直安慰自己鲜锚,他們只是感情好突诬,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,928評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著芜繁,像睡著了一般旺隙。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上骏令,一...
    開封第一講書人閱讀 51,718評(píng)論 1 305
  • 那天蔬捷,我揣著相機(jī)與錄音,去河邊找鬼榔袋。 笑死周拐,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的凰兑。 我是一名探鬼主播妥粟,決...
    沈念sama閱讀 40,442評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼吏够!你這毒婦竟也來(lái)了勾给?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,345評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤锅知,失蹤者是張志新(化名)和其女友劉穎播急,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體喉镰,經(jīng)...
    沈念sama閱讀 45,802評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡旅择,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,984評(píng)論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了侣姆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片生真。...
    茶點(diǎn)故事閱讀 40,117評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖捺宗,靈堂內(nèi)的尸體忽然破棺而出柱蟀,到底是詐尸還是另有隱情,我是刑警寧澤蚜厉,帶...
    沈念sama閱讀 35,810評(píng)論 5 346
  • 正文 年R本政府宣布长已,位于F島的核電站,受9級(jí)特大地震影響昼牛,放射性物質(zhì)發(fā)生泄漏术瓮。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,462評(píng)論 3 331
  • 文/蒙蒙 一贰健、第九天 我趴在偏房一處隱蔽的房頂上張望胞四。 院中可真熱鬧,春花似錦伶椿、人聲如沸辜伟。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)导狡。三九已至,卻和暖如春偎痛,著一層夾襖步出監(jiān)牢的瞬間旱捧,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工踩麦, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留枚赡,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,377評(píng)論 3 373
  • 正文 我出身青樓靖榕,卻偏偏與公主長(zhǎng)得像标锄,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子茁计,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,060評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容