File System Shell

Overview
The File System (FS) shell includes various shell-like commands that directly interact with the Hadoop Distributed File System (HDFS) as well as other file systems that Hadoop supports, such as Local FS, HFTP FS, S3 FS, and others. The FS shell is invoked by:

bin/hadoop fs <args>

appendToFile
Usage: hdfs dfs -appendToFile <localsrc> … <dst>

Append single src, or multiple srcs from local file system to the destination file system. Also reads input from stdin and appends to destination file system.
    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.

cat
Usage: hdfs dfs -cat URI [URI …]

Copies source paths to stdout.
Example:
    hdfs dfs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
    hdfs dfs -cat file:///file3 /user/hadoop/file4

copyFromLocal
Usage: hdfs dfs -copyFromLocal <localsrc> URI

Similar to put command, except that the source is restricted to a local file reference.
Options:
    The -f option will overwrite the destination if it already exists.

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

Similar to get command, except that the destination is restricted to a local file reference.

count
Usage: hdfs dfs -count [-q] <paths>

Count the number of directories, files and bytes under the paths that match the specified file pattern. 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
Example:
    hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
    hdfs dfs -count -q hdfs://nn1.example.com/file1

cp
Usage: hdfs dfs -cp [-f] URI [URI …] <dest>

Copy files from source to destination. This command allows multiple sources as well in which case the destination must be a directory.
Options:
 The -f option will overwrite the destination if it already exists.
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 …]

Displays sizes of files and directories contained in the given directory or the length of a file in case its just a file.
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

get
Usage: hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst>

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

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

Takes a source directory and a destination file as input and concatenates files in src into the destination local file. Optionally addnl can be set to enable adding a newline character at the end of each file.

ls
Usage: hdfs dfs -ls <args>

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

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

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 [-skipTrash] URI [URI …]

Delete files specified as args. Only deletes non empty directory and files. 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. Refer to rmr for recursive deletes.
Example:
    hdfs dfs -rm hdfs://nn.example.com/file /user/hadoop/emptydir

rmr
Usage: hdfs dfs -rmr [-skipTrash] URI [URI …]

Recursive version of delete. 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.
Example:
    hdfs dfs -rmr /user/hadoop/dir
    hdfs dfs -rmr hdfs://nn.example.com/user/hadoop/dir

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s