FileSystem shell

Contents

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, WebHDFS, S3 FS, and others. The FS shell is invoked by:

$ bin/hadoop fs <args>

All FS shell commands take path URIs as arguments. The URI format is scheme://authority/path. For HDFS the scheme is hdfs, and for the local FS the scheme is file. The scheme and authority are optional. If not specified, the default scheme specified in the configuration is used. An HDFS file or directory such as /parent/child can be specified as hdfs://namenodehost/parent/child or simply as /parent/child (given that your configuration is set to point to hdfs://namenodehost).

Most of the commands in FS shell behave like corresponding Unix commands. The difference is described for each command. Error information is sent to stderr and the output is sent to stdout.

If HDFS is being used, hdfs dfs is a synonym.

Relative paths can be used. For HDFS, the current working directory is the HDFS home directory /user/<username> that often has to be created manually. The HDFS home directory can also be implicitly accessed, e.g., when using the HDFS trash folder, the .Trash directory in the home directory.

Commands

Command Description

appendToFile

Appends sources from the local file system to the destination file system

cat

Prints the contents of a file to stdout

checksum

Returns the checksum information of a file

chgrp

Changes group association of files

chmod

Changes the permissions of files

chown

Changes the owner of files

copyFromLocal

Identical to the put command

copyToLocal

Identical to the get command

count

Counts the number of directories and files

cp

Copies files from source to destination

createSnapshot

Creates a snapshot of a snapshot table directory

deleteSnapshot

Deletes a snapshot from a snapshot table directory

df

Displays free space

du

Displays sizes of files and directories

dus

Displays a summary of file lengths

expunge

Permanently deletes files in checkpoints older than the retention threshold from the trash directory, and creates a new checkpoint

find

Finds all files that match the specified expression and applies selected actions to them

get

Copies files to the local file system

getfacl

Displays the ACLs of files and directories

getfattr

Displays the extended attribute names and values (if any) for a file or directory

getmerge

Takes a source directory and a destination file as inputted and concatenates files into the destination local file

head

Displays the first kilobyte of a file to stdout

help

Returns usage output

ls

Returns the file stats or list of its direct children for directory

lsr

Recursive version of ls

mkdir

Takes path URI’s as argument and creates directories

moveFromLocal

Identical to the put command

moveToLocal

Moves a file/directory from HDFS to the local file system

mv

Moves files from source to destination

put

Copies sources from the local file system to the destination file system

renameSnapshot

Renames a snapshot

rm

Deletes files specified as args

rmdir

Deletes a directory

rmr

Recursive version of rm

setfacl

Sets ACLs of files and directories

setfattr

Sets an extended attribute name and value for a file or directory

setrep

Changes the replication factor of a file

stat

Prints statistics about the file/directory in the specified format

tail

Displays last kilobyte of the file to stdout

test

Performs a test

text

Takes a source file and outputs the file in a text format

touch

Updates the access and modification times of the file specified by the URI to the current time

touchz

Creates a file of zero-length

truncate

Truncates all files that match the specified file pattern to the specified length

usage

Prints help for an individual command

Found a mistake? Seleсt text and press Ctrl+Enter to report it