FS Shell
Use bin/hadoop FS <args> to call the File System (fs) Shell Command. All FS shell commands use the URI path as the parameter. The URI format is scheme: // authority/path. For HDFS file systems, scheme is hdfs, for local file systems, and scheme is file. The scheme and authority parameters are optional. If not specified, the default scheme specified in the configuration will be used. An HDFS file or directory such as/parent/child can be expressed as hdfs: // namenode: namenodeport/parent/child, or simpler/parent/child (assuming that the default value in your configuration file is namenode: namenodeport ). The behavior of most FS Shell commands is similar to that of the corresponding Unix Shell commands. The differences are described as follows. The error message is output to stderr, and other information is output to stdout.
Cat
Usage:
hadoop fs -cat URI [URI …]
Output the content of the specified file in the path to stdout.
Example:
hadoop fs -cat hdfs://host1:port1/file1 hdfs://host2:port2/file2 hadoop fs -cat file:///file3 /user/hadoop/file4
Chgrp
Usage:
hadoop fs -chgrp [-R] GROUP URI [URI …]
Change the group to which the file belongs. Use-R to recursively change the directory structure. The user of the command must be the owner or super user of the file. For more information, see the HDFS permission user guide.
Chmod
Usage:
hadoop fs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI …]
Change the File Permission. Use-R to recursively change the directory structure. The user of the command must be the owner or super user of the file. For more information, see the HDFS permission user guide.
Chown
Usage:
hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]
Change the owner of a file. Use-R to recursively change the directory structure. The user of the command must be a Super User. For more information, see the HDFS permission user guide.
CopyFromLocal
Usage:
hadoop fs -copyFromLocal <localsrc> URI
Except that the source path is a local file, it is similar to the put command.
CopyToLocal
Usage:
hadoop fs -copyToLocal [-ignorecrc] [-crc] URI <localdst>
Except that the target path is a local file, it is similar to the get command.
Cp
Usage:
hadoop fs -cp URI [URI …] <dest>
Copy the file from the Source Path to the target path. This command allows multiple source paths. The target path must be a directory.
Example:
hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir
Du
Usage:
hadoop fs -du URI [URI …]
Displays the size of all files in the directory, or displays the size of this file when only one file is specified.
Example:
hadoop fs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://host:port/user/hadoop/dir1
Dus
Usage:
hadoop fs -dus <args>
Displays the file size.
Expunge
Usage:
hadoop fs -expunge
Clear the recycle bin. For more information about the recycle bin feature, see the HDFS design document.
Get
Usage:
hadoop fs -get [-ignorecrc] [-crc] <src> <localdst>
Copy the file to the local file system. You can use the-ignorecrc option to copy files that failed CRC verification. Use the-crc option to copy the file and CRC information.
Example:
hadoop fs -get /user/hadoop/file localfile hadoop fs -get hdfs://host:port/user/hadoop/file localfile
Getmerge
Usage:
hadoop fs -getmerge <src> <localdst> [addnl]
Accept a source directory and a target file as input, and connect all files in the source directory to the destination file at cost. Addnl is optional and is used to specify a line break at the end of each file.
Ls
Usage:
hadoop fs -ls <args>
If it is a file, the file information is returned in the following format:
File name <Number of replicas> file size modification date modification time permission user ID group ID
If it is a directory, a list of its direct sub-files is returned, just like in Unix. The list returned by the directory is as follows:
Directory name <dir> modify date modify time permission user ID group ID
Example:
hadoop fs -ls /user/hadoop/file1 /user/hadoop/file2 hdfs://host:port/user/hadoop/dir1 /nonexistentfile
Lsr
Usage:
hadoop fs -lsr <args>
Recursive version of the ls command. Similar to ls-R in Unix.
Mkdir
Usage:
hadoop fs -mkdir <paths>
Use the uri specified by the path as the parameter to create these directories. The behavior is similar to the mkdir-p of Unix. It creates parent directories of all levels in the path.
Example:
hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2 hadoop fs -mkdir hdfs://host1:port1/user/hadoop/dir hdfs://host2:port2/user/hadoop/dir
MovefromLocal
Usage:
hadoop fs -moveFromLocal <src> <dst>
Output a "not implemented" message.
Mv
Usage:
hadoop fs -mv URI [URI …] <dest>
Move the file from the Source Path to the target path. This command allows multiple source paths. The target path must be a directory. Files cannot be moved between different file systems.
Example:
hadoop fs -mv /user/hadoop/file1 /user/hadoop/file2 hadoop fs -mv hdfs://host:port/file1 hdfs://host:port/file2 hdfs://host:port/file3 hdfs://host:port/dir1
Put
Usage:
hadoop fs -put <localsrc> ... <dst>
Copy one or more source paths from the local file system to the target file system. You can also read the input from the standard input and write it to the target file system.
hadoop fs -put localfile /user/hadoop/hadoopfile hadoop fs -put localfile1 localfile2 /user/hadoop/hadoopdir hadoop fs -put localfile hdfs://host:port/hadoop/hadoopfile hadoop fs -put - hdfs://host:port/hadoop/hadoopfile
Read the input from the standard input.
Rm
Usage:
hadoop fs -rm URI [URI …]
Deletes a specified object. Delete only non-empty directories and files. Refer to the rmr command for Recursive deletion.
Example:
hadoop fs -rm hdfs://host:port/file /user/hadoop/emptydir
Rmr
Usage:
hadoop fs -rmr URI [URI …]
Recursive version of delete.
Example:
hadoop fs -rmr /user/hadoop/dir hadoop fs -rmr hdfs://host:port/user/hadoop/dir
Setrep
Usage:
hadoop fs -setrep [-R] <path>
Change the copy coefficient of a file. The-R option is used to recursively change the copy coefficient of all files in the directory.
Example:
hadoop fs -setrep -w 3 -R /user/hadoop/dir1
Stat
Usage:
hadoop fs -stat URI [URI …]
Returns the statistics of the specified path.
Example:
hadoop fs -stat path
Tail
Usage:
hadoop fs -tail [-f] URI
Output 1 kb at the end of the file to stdout. The-f option is supported, and the behavior is consistent with that in Unix.
Example:
hadoop fs -tail pathname
Test
Usage:
hadoop fs -test -[ezd] URI
Option:
-E: Check whether the file exists. If yes, 0 is returned.
-Z: Check whether the file is 0 bytes. If yes, 0 is returned.
-D if the path is a directory, 1 is returned; otherwise, 0 is returned.
Example:
hadoop fs -test -e filename
Text
Usage:
hadoop fs -text <src>
Output the source file in text format. The allowed formats are zip and TextRecordInputStream.
Touchz
Usage:
hadoop fs -touchz URI [URI …]
Create a 0-byte empty file.
Example:
hadoop -touchz pathname