0% found this document useful (0 votes)
496 views

Hadoop HDFS Commands

This document describes basic HDFS commands for interacting with files and directories in HDFS. It provides the syntax and examples of commands for getting the Hadoop version, listing files and directories, creating directories, getting file summaries, creating empty files, copying files between local and HDFS, putting and getting files, counting files, and removing files and directories from HDFS.

Uploaded by

Kishore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
496 views

Hadoop HDFS Commands

This document describes basic HDFS commands for interacting with files and directories in HDFS. It provides the syntax and examples of commands for getting the Hadoop version, listing files and directories, creating directories, getting file summaries, creating empty files, copying files between local and HDFS, putting and getting files, counting files, and removing files and directories from HDFS.

Uploaded by

Kishore
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

HDFS Commands

This document will help you understand the basic Hadoop commands, using which you can
perform different operations on hdfs.
Note: Please do not copy paste the commands, instead type them manually on the terminal.

Command to find the Version of Hadoop:


Command: hadoop version

LS command:
Displays List of Files and Directories in HDFS file Path
Command: hadoop dfs ls /

MKDIR command:
It creates the directory in HDFS
Syntax: hdfs dfs mkdir /directory_name

E.g: hdfs dfs mkdir /new_edureka

DU command:
Displays the summary of file lengths.
Syntax: hdfs dfs du s /path/to/file_in_hdfs
Command: hdfs dfs du s /new_edureka/test
Note: Here test is a file that exists in HDFS in the directory new_edureka

TOUCHZ command:
Create a file in HDFS with file size 0 bytes
Syntax: hdfs dfs touchz /directory/filename
E.g: hdfs dfs touchz /newedureka/sample.
Note: Here we are trying to create a file named sample in the directory new_edureka of
hdfs with file size 0 bytes.

Use the du command to check the file size


Command: hdfs dfs du s /new_edureka/sample

CAT command:
Copies source paths to stdout.
Syntax: hdfs dfs cat /path/to/file_in_hdfs
Command: hdfs dfs cat /new_edureka/test
Note: Here test is a file that exists in HDFS in the directory new_edureka

TEXT command:
Takes a source file and outputs the file in text format.( Same as Cat command )
Syntax: hdfs dfs text /path/to/file_in_hdfs
Command: hdfs dfs text /new_edureka/test
Note: Here test is a file that exists in HDFS in the directory new_edureka

copyFromLocal command :
Copy the file from Local file system to HDFS.
Syntax: hdfs fs -copyFromLocal <localsrc> URI

E.g: hdfs dfs copyFromLocal /home/edureka/Desktop/test /new_edureka


Note: Here test is the file present in the local directory - /home/edureka/Desktop

copyToLocal command :
Copy the file from HDFS to Local File System.
Syntax: hdfs fs -copyToLocal URI <localdst>
Command: hdfs dfs copyToLocal /new_edureka/test /home/edureka
Note: Here test is a file present in new_edureka directory of HDFS

PUT command:
Copy single source, or multiple srcs from local file system to the destination file system.
Syntax: hdfs fs -put <localsrc> ... <dst>
Command: hdfs dfs put /home/edureka/Desktop/test /user

Note: copyFromLocal is similar to put command, except that the source is restricted to a
local file reference

GET command:
Copy files from hdfs to the local file system.
Syntax: hadoop fs -get [-ignorecrc] [-crc] <src> <localdst>
E.g: hdfs dfs get /user/test /home/edureka

Note: copyToLocal is similar to get command, except that the destination is restricted to a
local file reference.
COUNT command:
Count the number of directories, files and bytes under the paths that match the specified file
pattern.
Command: hdfs dfs count /user

RM command:
Remove the file from HDFS.
Syntax: hdfs dfs rm /path/to/file_in_hdfs
Command: hdfs dfs rm /new_edureka/test

RMR command:
Remove the directory to HDFS
Syntax: hdfs dfs rmr /path/to/directory_in_hdfs
Command: hdfs dfs rmr /new_edureka/

You might also like