First, execute the following query in the psql terminal.
select 'drop database "'||datname||'";'
from pg_database
where datistemplate=false;
This will generate drop database
command for all the databases. Copy the result in a text editor and exclude(delete) what you want to keep and save it as dd.sql
file. And execute it like this:
psql -d postgres -f dd.sql