- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
hdfs file exists check
- Labels:
-
Apache Hadoop
Created ‎08-03-2016 01:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am performing a basic check to see if a file exists in HDFS or not. I am using hdfs dos -test command for the same. But it doesn't seem to work correctly. In the documentation its mentioned as it would return 0 if the file exists. But I am not getting any output when the command is run. Let me know what need to be done to get this working. Please see the screenshot attached Thanks
Created ‎08-03-2016 01:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@bigdata.neophyte The hdfs command doesn't print the result but sets it's return code to the shell. You'll need to test the return code from the 'hdfs dfs -test' command. On Linux try this:
hdfs dfs -test -e /tmp echo $? hdfs dfs -test -e /this_doesnt_exist echo $?
Created ‎08-03-2016 01:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@bigdata.neophyte The hdfs command doesn't print the result but sets it's return code to the shell. You'll need to test the return code from the 'hdfs dfs -test' command. On Linux try this:
hdfs dfs -test -e /tmp echo $? hdfs dfs -test -e /this_doesnt_exist echo $?
Created ‎08-03-2016 02:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks @Terry Stebbens
Created ‎08-03-2016 01:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@bigdata.neophyte Here is the usage -
Usage: hadoop fs -test -[defsz] URI
Options:
- -d: f the path is a directory, return 0.
- -e: if the path exists, return 0.
- -f: if the path is a file, return 0.
- -s: if the path is not empty, return 0.
- -z: if the file is zero length, return 0.
Example:
- hadoop fs -test -e filename
Check - http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/FileSystemShell.html#test
Created ‎08-14-2018 08:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Team , Is there any way to test multiple files exist or not in single command?? like below.. pls suggest
- hadoop fs -test -e filename1 filename2
