Hadoop FS Shell stat

HadoopHadoopBeginner
Practice Now

Introduction

In this lab, we will explore the Hadoop HDFS skill point "FS Shell stat" within the context of a scenario set in the legendary tale of a sunken shipwreck treasure cove. Imagine a scenario where the undiscovered treasures of a sunken ship are said to be buried deep within the ocean floor of the Treasure Cove. You play the role of a renowned narrator of this treasure hunting legend whose task is to guide explorers to uncover the hidden riches.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL hadoop(("`Hadoop`")) -.-> hadoop/HadoopHDFSGroup(["`Hadoop HDFS`"]) hadoop/HadoopHDFSGroup -.-> hadoop/fs_stat("`FS Shell stat`") subgraph Lab Skills hadoop/fs_stat -.-> lab-271877{{"`Hadoop FS Shell stat`"}} end

Exploring FS Shell stat

In this step, we will delve into the hadoop fs -stat command to gather detailed information about a specific file in Hadoop HDFS.

  1. switch to the hadoop user:
    su - hadoop
  2. create a file named treasure.txt in the current directory:
    vim treasure.txt
  3. the content in treasure.txt is:
    hello world
  4. put the treasure.txt file into the Hadoop file system:
    hadoop fs -put treasure.txt /user/hadoop/
  5. Use the following command to display the attributes of a file named treasure.txt in the Hadoop file system:
    hadoop fs -stat %g-%F-%b-%y-%Y-%o /user/hadoop/treasure.txt
    the parameters in the command are:
    %g: Group name of owner
    %F: File type
    %b: Length in bytes
    %y: Modification timestamp
    %Y: Access timestamp
    %o: Block size
  6. The output will provide information such as file permissions, file type, modification time, access time, and block size. like this:
    supergroup-regular file-12-2024-03-08 12:42:00-1709901720659-134217728

Analyzing File Permissions

In this step, we will focus on understanding and analyzing the file permissions using the hadoop fs -stat command.

  1. Execute the following command to view the file permissions of the treasure.txt file:
    hadoop fs -stat %F-%A /user/hadoop/treasure.txt
    the parameters in the command are:
    %F: File type
    %A: File permissions
  2. The output will display the file type and permissions associated with the file. like this:
    regular file-rw-r--r--

Summary

In this lab, we explored the hadoop fs -stat command within the Hadoop HDFS environment to retrieve detailed file information. By following the step-by-step guide, users can gain a better understanding of how to utilize this command for file attribute analysis and permission verification in Hadoop. This lab aims to provide hands-on experience for beginners to familiarize themselves with FS Shell stat operations in Hadoop.

Other Hadoop Tutorials you may like