2 HDFS Commands
2 HDFS Commands
2 HDFS Commands
Assignment needs to be submitted in the Microsoft Word. The file should contain the
following points:
1. Usage
2. Example
3. Syntax which you have used to execute the HDFS commands
4. Screenshot of the output (As shown in Example 1.1)
1.1 count
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
Example:
Exit Code:
Output:
1.2 cat
Example:
Exit Code:
1.3 chmod
Usage: hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]
Change the permissions of files. With -R, make the change recursively through the directory
structure. The user must be the owner of the file, or else a super-user. Additional information
is in the Permissions Guide.
Options
The -R option will make the change recursively through the directory structure.
1.4 copyFromLocal
Similar to put command, except that the source is restricted to a local file reference.
Options:
1.5 copyToLocal
Similar to get command, except that the destination is restricted to a local file reference.
1.6 cp
Copy files from source to destination. This command allows multiple sources as well in
which case the destination must be a directory.
Options:
Example:
• hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2
• hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir
Exit Code:
1.7 du
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:
1.8 get
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:
Exit Code:
1.9 ls
For a directory it returns list of its direct children as in Unix. A directory is listed as:
Example:
Exit Code:
1.10 lsr
1.11 mkdir
Options:
• The -p option behavior is much like Unix mkdir -p, creating parent directories along
the path.
Example:
Exit Code:
1.12 moveFromLocal
1.13 moveToLocal
1.14 mv
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:
Exit Code:
1.15 put
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.
Exit Code:
1.16 rm
Example:
Exit Code:
1.17 rmr
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:
Exit Code:
1.18 tail
Options:
• The -f option will output appended data as the file grows, as in Unix.
Example:
Takes a source file and outputs the file in text format. The allowed formats are zip and
TextRecordInputStream.
1.20 touchz
Example: