Listing Files and Directories in HDFS
One of the most common operations in HDFS is listing the files and directories in the file system. The HDFS FS Shell provides several commands for this purpose, allowing you to view the contents of HDFS directories and retrieve information about files and directories.
Listing the Root Directory
To list the contents of the HDFS root directory, you can use the following command:
$ hdfs dfs -ls /
This will display a list of all the files and directories in the root directory, including their permissions, owner, group, size, and modification time.
Listing a Specific Directory
To list the contents of a specific directory in HDFS, you can use the following command:
$ hdfs dfs -ls /user/example
This will display the contents of the /user/example
directory.
Recursive Listing
If you want to list the contents of a directory and its subdirectories recursively, you can use the -R
option:
$ hdfs dfs -ls -R /user/example
This will display the contents of the /user/example
directory and all its subdirectories.
Displaying File and Directory Details
To display more detailed information about files and directories in HDFS, you can use the -stat
option. This will show the file or directory size, replication factor, block size, and other metadata:
$ hdfs dfs -stat /user/example/file.txt
This will display the detailed information for the file.txt
file in the /user/example
directory.
By using these HDFS FS Shell commands, you can effectively list and explore the contents of your HDFS file system, which is an essential skill for working with Hadoop and big data applications.