raspi-config –expand-rootfs

If using the official Raspian images released by the Raspberry Pi Foundation, you can use the raspi-config utility to resize the main partition to fill the SD card. Instructions are on the RPi raspi-config page. Read on if you want to know if you should use it.

The raspi-config tool is fully automatic. All you have to do is launch it, select the option expand_rootfs in the raspi-config menu, and reboot the Raspberry Pi. It takes some time for the changes to be made. Once it’s finished, the Pi returns to a command-line or graphical login prompt.

Alternatively, you can just run raspi-config –expand-rootfs to make it a completely non-interactive process.