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:
-