How to see the list of the Postgres databases via the linux terminal? I have connected a database using the command
sudo -i -u postgres

And after I have tried \l  and \d too, to view the list of all available databases, it is not working. Instead, I get the following output:
d:command not found and 
l:command not found error is showing 

What to do, how to get the list of the postgresql databases?
If you want to execute the command from the shell, you can use the -c option in psql:

psql -c '\l'


Example:

peter@blackrain:~$ sudo su  postgres
postgres@blackrain:/home/peter$ psql -c '\l'
                                  List of databases
    Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
------------+----------+----------+-------------+-------------+-----------------------
 blackrain  | peter    | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 postgres   | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 redpepper  | peter    | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres
 template1  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
            |          |          |             |             | postgres=CTc/postgres
 x          | peter    | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
(6 rows)

postgres@blackrain:/home/peter$