How to find expiry date of SSL certificate [linux]

How to easily check whether the certificate has expired or not.

My bash command
You can use, all dates (creating and expiring):

openssl x509 -enddate -noout -in /etc/pki/tls/certs/localhost.crt

You can use, only expiring date:

openssl x509 -dates -noout -in /etc/pki/tls/certs/localhost.crt

Bash script to list multiple certificates in order of their expiration, most recently expiring first:

for pem in /etc/pki/tls/certs/*.crt; do
   printf '%s: %s\n' \
      "$(date --date="$(openssl x509 -enddate -noout -in "$pem"|cut -d= -f 2)" --iso-8601)" \
      "$pem"
done | sort