Online Tutorials & Training Materials | STechies.com
Register Login

HDFS Shell Commands Guide

|| || 0

HDFS Shell Commands Guide
Stechies

 Explore some of the important commands that are available in the Hadoop Distributed File System. 

1) The following command will list out all the files and directories present within the root directory of Hadoop Distributed File System (HDFS).

hdadmin@namenode data]$ hadoop fs -ls hdfs://namenode:8000/

2) This command will list out all the files and directories within the / data directory.

hdadmin@namenode data]$ hadoop fs -ls hdfs://namenode:8000/data

3) This command will display the contents of the following file on the terminal and this file is present within the Hadoop distributed file system.

hdadmin@namenode data]$ Hadoop fs -cat /data/The and The Mind.txt

The contents of the file are being displayed.

4) This command will delete the following file. 

[hdadmin@namenode data]$ hadoop fs -rm /data/The Senses and The Mind.txt
Deleted hdfs://namenode:8000/data/The Senses and The Mind.txt
[hdadmin@namenode data]$

You can confirm it on the web UI. 

Neither we are able to list out this file on the command line since this file was deleted.

[hdadmin@namenode data]$ hadoop fs -ls /data/The Senses and The Mind.txt
ls: Cannot access /data/The Senses and The Mind.txt: No such file or directory
[hdadmin@namenode data]$

5) This command will delete the entire directory. You will not find the directory on the web UI.

[hdadmin@namenode data]$ hadoop fs -rmr /data
Deleted
hdfs://namenode:8000/data
[hdadmin@namenode data]$

This command will create an Empty file on the Hadoop distributed file system.

[hdadmin@namenode data]$ hadoop fs -touchz /data/HelloWorld.txt

Listing out the created file. You will see the file is present within the /data directory. You can confirm it on the web UI, it shows that it is an empty file.

The following command will create a directory on the Hadoop distributed file system. Creating a directory called ‘test’.

You can see the test directory.

Remove this directory. If you list out again, you won't be able to see this directory as this directory was deleted.


Related Articles

0.0107 seconds.