How to navigate directories in Hadoop HDFS

2Big2BeSmall picture 2Big2BeSmall · Oct 10, 2015 · Viewed 54.7k times · Source

I would like to navigate in HDFS

First i looked on the directories in "root" HDFS

[cloudera@localhost ~]$ sudo -u hdfs hadoop fs -ls hdfs:/
Found 5 items
drwxr-xr-x   - hbase hbase               0 2015-10-10 07:03 hdfs:///hbase
drwxr-xr-x   - solr  solr                0 2014-06-01 16:16 hdfs:///solr
drwxrwxrwx   - hdfs  supergroup          0 2015-10-08 11:45 hdfs:///tmp
drwxr-xr-x   - hdfs  supergroup          0 2015-04-13 08:26 hdfs:///user
drwxr-xr-x   - hdfs  supergroup          0 2014-06-01 16:15 hdfs:///var

then i tried entering one of them

[cloudera@localhost ~]$ sudo -u hdfs hadoop -cd hdfs:///hbase
Error: No command named `-cd' was found. Perhaps you meant `hadoop cd'

trying also 'hadoop cd' do not work

[cloudera@localhost ~]$ sudo -u hdfs hadoop cd hdfs:///hbase
Exception in thread "main" java.lang.NoClassDefFoundError: cd
Caused by: java.lang.ClassNotFoundException: cd
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: cd.  Program will exit.

Please don't offer to use -ls -R (recursive) to show all files .

I want to be able navigate using commands like cd

Answer

YoungHobbit picture YoungHobbit · Oct 10, 2015

There is no cd (change directory) command in hdfs file system. You can only list the directories and use them for reaching the next directory.

You have to navigate manually by providing the complete path using the ls command.

hdfs dfs -ls /user/username/app1/subdir/