I tried to do hdfs dfs -pwd
, but that command does not exist.
So currently I am resorting to doing hdfs dfs -ls ..
followed by hdfs dfs -ls ../..
.
I also looked at the command listing for hdfs dfs
but did not see anything that looked promising.
Is there a more direct way to find the absolute path?
"hdfs dfs -pwd" does not exist because there is no "working directory" concept in HDFS when you run commands from command line.
You cannot execute "hdfs dfs -cd" in HDFS shell, and then run commands from there, since both HDFS shell and "hdfs dfs -cd" commands do not exist too, thus making the idea of working directory redundant.
Your home dir is always the prefix of the path, unless it starts from "/".
There is no -cd
command, so I guess you expect -pwd
to return the home directory.
According to this related question: HDFS Home Directory, the home directory of hdfs is always /user/<ShortUserName>
(it is hardcoded in the source).
If you want to see the absolute path of home directory,you can make a empty directory and delete it,the information can show you the absolute path.
[test@test ~]$ hadoop fs -mkdir t1
[test@test ~]$ hadoop fs -rm -r t1
17/02/14 10:00:46 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 1 minutes, Emptier interval = 0 minutes.
Moved: 'hdfs://nameservice1/user/test/t1' to trash at: hdfs://nameservice1/user/test/.Trash/Current
'hdfs://nameservice1/user/test/t1' is the absolute path of the t1 directory
There is no such PWD, CD suportability in hadoop like unix/linux.
The possible Hadoop commands are
hadoop fs
-appendToFile
-cat
-checksum
-chgrp
-chmod
-chown
-copyFromLocal
-copyToLocal
-count
-cp
-createSnapshot
-deleteSnapshot
-df
-du
-expunge
-get
-getfacl
-getfattr
-getmerge
-help
-ls
-mkdir
-moveFromLocal
-moveToLocal
-mv
-put
-renameSnapshot
-rm
-rmdir
-setfacl
-setfattr
-setrep
-stat
-tail
-test
-text
-touchz
-usage
There is no equivalent of the pwd
command in the file system shell utility hdfs dfs
, but here's a workaround using mkdir
and find
:
$ hdfs dfs -mkdir xYz
$ hdfs dfs -find / -name "xYz"
(where "xYz" is an unused file name)
In one command:
$ echo $(dirname $(hdfs dfs -rm -R xYz>/dev/null 2>&1;hdfs dfs -mkdir xYz&&hdfs dfs -find / -name "xYz"))
There's the hdfs.pwd() function, but you unfortunately cannot use it from the command line. HDFS User's Guide