The hadoop fs -ls command allows you to view the files and directories in your HDFS filesystem, much as the ls command works on Linux / OS X / *nix.
Default Home Directory in HDFS
A user’s home directory in HDFS is located at /user/userName. For example, my home directory is /user/akbar.
List the Files in Your Home Directory
hadoop fs -ls defaults to /user/userName, so you can leave the path blank to view the contents of your home directory.
hadoop fs -ls
Recursively List Files
The following command will recursively list all files in the /tmp/hadoop-yarn directory.
hadoop fs -ls -R /tmp/hadoop-yarn
Show List Output in Human Readable Format
Human readable format will show each file’s size, such as 1461, as 1.4k.
hadoop fs -ls -h /user/akbar/input
You will see output similar to:
-rw-r–r– 1 akbar akbar 1.4k 2012-06-25 16:45 /user/akbar/input/core-site.xml
-rw-r–r– 1 akbar akbar 1.8k 2012-06-25 16:45 /user/akbar/input/hdfs-site.xml
-rw-r–r– 1 akbar akbar 1.3k 2012-06-25 16:45 /user/akbar/input/mapred-site.xml
-rw-r–r– 1 akbar akbar 2.2k 2012-06-25 16:45 /user/akbar/input/yarn-site.xml
List Information About a Directory
By default, hadoop fs -ls shows the contents of a directory. But what if you want to view information about the directory, not the directory’s contents?
To show information about a directory, use the -d option.
hadoop fs -ls -d /user/akbar
drwxr-xr-x – akbar akbar 0 2012-07-07 02:28 /user/akbar/
Compare the output above to the output without the -d option:
drwxr-xr-x – akbar akbar 0 2012-06-25 16:45 /user/akbar/input
drwxr-xr-x – akbar akbar 0 2012-06-25 17:09 /user/akbar/output
-rw-r–r– 1 akbar akbar 3 2012-07-07 02:28 /user/akbar/text.hdfs
Show the Usage Statement
hadoop fs -usage ls
The output will be:
Usage: hadoop fs [generic options] -ls [-d] [-h] [-R] [ ...]