How to expand ext4 filesystem to fill partition with command line on ubuntu?

ubuntu filesystem

When resizing partition, the filesystem need to be resized too. This can be done online, without even unmounting. The command to expand partition is resize2fs and be default it will fill all available space. Only device name is required as parameter:

Example:

sudo resize2fs /dev/sdb

Example output:

resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sdb is mounted on /var; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/sdb is now 3145728 (4k) blocks long.

This will result in filesystem grow:

[localhost:~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb        9,8G  8,9G  350M  97% /test

After applying command:

[localhost:~]$ df -h
Filesystem Size Used Avail Use% Mounted on /dev/sdb 12G 8,9G 2,3G 81% /test
patrick-lindenberg-191841-unsplash.jpg