command to check RAM slots in motherboard?

You can use this command:

sudo lshw -class memory 

It will give you an output like this:

 *-memory
       description: System Memory
       physical id: 33
       slot: System board or motherboard
       size: 4GiB
     *-bank:0
          description: DIMM [empty]
          physical id: 0
          slot: ChannelA-DIMM0
     *-bank:1
          description: DIMM [empty]
          physical id: 1
          slot: ChannelA-DIMM1
     *-bank:2
          description: SODIMM DDR3 Synchronous 1333 MHz (0.8 ns)
          product: AD73I1C1674EV
          vendor: Fujitsu
          physical id: 2
          serial: 43D30100
          slot: ChannelB-DIMM0
          size: 2GiB
          width: 64 bits
          clock: 1333MHz (0.8ns)
     *-bank:3
          description: DIMM [empty]
          physical id: 3
          slot: ChannelB-DIMM1

Here in my system I have 4 memory slots in which currently I am using only one slot. In other slots you can see it shows empty.

For maximum supportable memory use:

sudo dmidecode -t 16

or

sudo dmidecode -t memory

or

 sudo dmidecode | grep -i "Maximum Capacity:" | uniq

EDIT: more interactive way to see Slot use small script (suggested by Serg)

sudo lshw -class memory | awk '/bank/ {count++} END {print "You have " count " slots for RAM"}'

Another way to get all the numbers directly;

To get the total number of slots:

sudo dmidecode -t memory | grep -c '^Memory Device$'

To get the number of slots used:

sudo dmidecode -t memory | grep -c -Po '^\tPart Number: (?!\[Empty\])'

To get the maximum capacity:

sudo dmidecode -t memory | grep -Po '^\tMaximum Capacity: \K.*'
ubuntu@ubuntu ~ % sudo dmidecode -t memory | grep -c '^Memory Device$'
4
ubuntu@ubuntu ~ % sudo dmidecode -t memory | grep -c -Po '^\tPart Number: (?!\[Empty\])'
1
ubuntu@ubuntu ~ % sudo dmidecode -t memory | grep -Po '^\tMaximum Capacity: \K.*'
32 GB

The number of memory devices in the results of sudo dmidecode --type 17 is equal to the number of memory slots, so the command to print the number of RAM slots is:

sudo dmidecode --type 17 | grep 'Memory Device' --count  

The results of this command will be one integer number equal to the number of RAM slots.

The command to show the size of each of the installed RAM sticks is:

 sudo dmidecode --type 17 | grep -i size  

This is a very informative command because it shows the number of empty RAM slots, the number of RAM slots that have RAM sticks installed and the size of each installed RAM stick.

The command to show the maximum RAM capacity (the maximum size that you can increase the RAM to) is:

sudo inxi -m | grep capacity 

This example output shows that the computer has 4 RAM slots (2 empty slots & 2 full slots), and two 4GB RAM sticks (8GB RAM).

$ sudo dmidecode --type 17 | grep 'Memory Device' --count
4
$ sudo dmidecode --type 17 | grep -i size
    Size: No Module Installed
    Size: No Module Installed
    Size: 4096 MB
    Size: 4096 MB   
$ sudo inxi -m | grep capacity
   Array-1 capacity: 32 GB devices: 4 EC: None

dmidecode shows the number of slots available for the controller. There are up to 4 DMI types, 2 can be memory arrays, and 2 can be specific slots. 2 are less common. The information in dmidecode/inxi is extremely unreliable when it comes to the array data, but the actual slot data is generally very reliable. If you are looking into buying or upgrading RAM, you should always check the product specifications to make sure that what inxi/dmidecode reports is actually correct. This goes in particular for maximum RAM size and array capacities.*