How to obtain .bed file with coordinates of all genes
Via Gencode and BEDOPS convert2bed:

$ wget -qO- ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz \
    | gunzip --stdout - \
    | awk '$3 == "gene"' - \
    | convert2bed -i gff - \
    &gt; genes.bed


You can modify the awk statement to get exons, by replacing gene with exon.

BEDOPS: https://github.com/bedops/bedops

This is based off an answer I wrote on Biostars, which includes a Perl script for generating a BED file of introns from gene and exon annotations: https://www.biostars.org/p/124515/#124522