Explore Courses Blog Tutorials Interview Questions
0 votes
in Big Data Hadoop & Spark by (11.4k points)

I would like to know is there any command/expression to get only the file name in hadoop. I need to fetch only the name of file, when I do hadoop fs -ls it prints the whole path.

I tried below but just wondering if some better way to do it.

hadoop fs -ls <HDFS_DIR>|cut -d ' ' -f17

1 Answer

0 votes
by (32.3k points)
edited by

Try the command below and get the file names only:

$ hdfs dfs -ls /user | awk -F'/' '{print $NF}'


For more information regarding Hadoop, refer to the following video tutorial:

Browse Categories