gsutil Cheatsheet

Check Directory Size

gsutil du -sh gs://<path_to_directory>

Find the latest file in the directory

gsutil ls -l  gs://<path_to_directory>  | sort -k 2 | tail -1

Find the oldest file in the directory

gsutil ls -l gs://<path_to_directory>  | sort -k 2 | head -2

Remove the files older than some time

For example let us say we want to delete the files created in year 2020

gsutil ls -l gs://<path_to_directory> | egrep 2020 | awk '{print $3}' | gsutil -m rm -I