HDFS offers a command-line utility where we can execute HDFS shell commands. These commands are very much similar to Linux-based commands.
File System commands can be used to directly interact with HDFS. These commands can also be executed on an HDFS supported File System such as WebHDFS, S3, and so on. Let's walk through a few basic, important commands:
-ls
: Thels
command lists all the directories and files within a specified path:
hadoop fs -ls /user/packt/
The ls
command returns the following information:
File_Permission numberOfReplicas userid groupid filesize last_modification_date last_modification_time filename/directory_name
A few options are also available that you can use with the ls
command, such as sorting output based on size and showing only limited information:
hadoop fs -ls -h /user/packt
The -h
option is used to display file sizes in a readable format. For example, it would use 230.8 MB or 1.24 GB instead of putting the file size...