regexfilenameslsminio

How to get just filename from minio (mc) ls


I need to retrieve the filename for a bash script. I thought mc ls could do all that ls can do, but I seem to be mistaken. So now I'm struggling with regex.

When I do mc ls minio/bucket1/, I'll get:

[2021-05-14 11:15:18 CEST]     0B files1/
[2021-05-14 11:15:18 CEST]     0B files2/
[2021-05-14 11:15:19 CEST]     0B file1.ext
[2021-05-14 11:15:18 CEST]     0B file2.ext

How can I extract just the filename in bash?


Solution

  • You can pipe the following sed command after your mc ls command:

    sed -n 's/^\[[^][]*][[:blank:]]*[^[:blank:]]*[[:blank:]]\(.*\.gpkg\)$/\1/p'
    

    See the online demo.

    Details: