Delete files older than 10days on HDFS

前端 未结 5 2108
难免孤独
难免孤独 2020-12-08 22:15

Is there a way to delete files older than 10 days on HDFS?

In Linux I would use:

find /path/to/directory/ -type f -mtime +10 -name \'*.txt\' -execdir         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 22:48

    How about this:

    hdfs dfs -ls /tmp    |   tr -s " "    |    cut -d' ' -f6-8    |     grep "^[0-9]"    |    awk 'BEGIN{ MIN=14400; LAST=60*MIN; "date +%s" | getline NOW } { cmd="date -d'\''"$1" "$2"'\'' +%s"; cmd | getline WHEN; DIFF=NOW-WHEN; if(DIFF > LAST){ print "Deleting: "$3; system("hdfs dfs -rm -r "$3) }}'
    

    A detailed description is here.

提交回复
热议问题