Friday, 29 September 2017

The
File System (FS) shell includes different shell-like commands that directly interrelate
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

Hadoop
file system (fs) shell commands are used to perform various file operations
like copying file, changing permissions, viewing the contents of the file,
changing ownership of files, creating directories etc.

ls

The
hadoop ls command is used to show the directories and files. An example is
shown below

c:\hadoop-2.3.0\bin>hadoop fs -ls
/

Found 5 items

drwxr-xr-x - TNC supergroup 0 2017-10-11 19:14 /mir

drwx------ - TNC supergroup 0 2017-10-11 19:58 /tmp

drwxr-xr-x - TNC supergroup 0 2017-10-11 19:46 /wcop

drwxr-xr-x - TNC supergroup 0 2017-10-11 20:00 /wcop1

drwxr-xr-x - TNC supergroup 0 2017-10-11 23:58 /wcop2

ls –R

The
hadoop lsr command recursively shows the directories, sub directories and files
in the specified directory. The usage example is shown below:

c:\hadoop-2.3.0\bin>hadoop fs -ls
-R /wcop1

-rw-r--r-- 1 TNC supergroup 0 2017-10-11 20:00 /wcop1/_SUCCESS

-rw-r--r-- 1 TNC supergroup 20 2017-10-11 19:59
/wcop1/part-r-00000

Cat

Hadoop
cat command is used to print the contents of the file on the terminal (stdout).
The usage example of hadoop cat command is shown below:

c:\hadoop-2.3.0\bin>hadoop fs -ls
-R /wcop1

-rw-r--r-- 1 TNC supergroup 0 2017-10-11 20:00 /wcop1/_SUCCESS

-rw-r--r-- 1 TNC supergroup 20 2017-10-11 19:59
/wcop1/part-r-00000

Chmod

The
hadoop chmod command is used to change the permissions of files. The -R option
can be used to recursively change the permissions of a directory.

c:\hadoop-2.3.0\bin>hadoop fs
-chmod 777 /HdoopTutorial

Mkdir

The
hadoop mkdir command is for creating directories in the hdfs. You can use the -p option for creating
parent directories. This is like to the unix mkdir command. The usage example
is shown below:

c:\hadoop-2.3.0\bin>hadoop fs
-mkdir /HadoopTutorial

c:\hadoop-2.3.0\bin>hadoop fs -ls
/

Found 6 items

drwxr-xr-x - TNC supergroup 0 2017-10-14 20:37 /HadoopTutorial

drwxr-xr-x - TNC supergroup 0 2017-10-11 19:14 /mir

drwx------ - TNC supergroup 0 2017-10-11 19:58 /tmp

drwxr-xr-x - TNC supergroup 0 2017-10-11 19:46 /wcop

drwxr-xr-x - TNC supergroup 0 2017-10-11 20:00 /wcop1

drwxr-xr-x - TNC supergroup 0 2017-10-11 23:58 /wcop2

copyFromLocal

The hadoop
copyFromLocal command is used to copy a file from the local file system to the
hadoop hdfs. The syntax and usage example
are shown below: