Q:

Getting wrong result while looking for avro files inside a HDFS directory

I would like to check if there is one or more avro files available inside a HDFS location 
[cloudera@client01 scripts]$ hdfs dfs -ls /user/cloudera/output_files/file_date_2017-04-05

Found 11 items
-rw-rw----   2 cloudera cloudera          0 2017-04-24 13:57 /user/cloudera/output_files/file_date_2017-04-05/_SUCCESS
-rw-rw----   2 cloudera cloudera     781714 2017-04-24 13:56 /user/cloudera/output_files/file_date_2017-04-05/part-r-00000-7e1d4e4e-9166-4744-b73b-095a7cc0e090.avro
-rw-rw----   2 cloudera cloudera     782132 2017-04-24 13:56 /user/cloudera/output_files/file_date_2017-04-05/part-r-00001-7e1d4e4e-9166-4744-b73b-095a7cc0e090.avro
-rw-rw----   2 cloudera cloudera     782467 2017-04-24 13:56 /user/cloudera/output_files/file_date_2017-04-05/part-r-00002-7e1d4e4e-9166-4744-b73b-095a7cc0e090.avro
-rw-rw----   2 cloudera cloudera     785117 2017-04-24 13:56 /user/cloudera/output_files/file_date_2017-04-05/part-r-00003-7e1d4e4e-9166-4744-b73b-095a7cc0e090.avro

But when i apply the below hdfs command i get nothing.
[cloudera@client01 scripts]$  hdfs dfs -ls /user/cloudera/output_files/file_date_2017-04-05/* | grep "part*.avro"
[cloudera@client01 scripts]$ echo $?
1
[cloudera@client01 scripts]$  hdfs dfs -ls /user/cloudera/output_files/file_date_2017-04-05/ | grep "part*.avro"
[cloudera@client01 scripts]$ echo $?
1

I am expecting 0 to be printed as there are many avro files located inside the HDFS location.
Could someone help me on what went wrong on this above command

A:

Here, you would need .* to match zero or more characters between the filename pattern in grep.
hdfs dfs -ls /user/cloudera/output_files/file_date_2017-04-05/ | grep "part.*\.avro"

Or, you can use -test if need only the exit code.
hdfs dfs -test -e /user/cloudera/output_files/file_date_2017-04-05/part*.avro
echo $?
0

