How can I find size the of all partitions in Ubuntu with a command that saves to name.txt?


If you want to find the size of all the partitions and save it to a file: you have to run this command:

df -h | grep /dev > name.txt

It will find the size of all the partitions including swap and save it to your file name.txt. where udev is nothing but the swap

or simply:

df -h > name.txt

If you want to get the size of all devices available to your computer and want to save in file then you can execute this command:

lsblk | awk '{print $1 "       \t    " $4}' > name.txt

It will save only the partition and the size

  • 2
    This will only show the size of the mounted partitions. – MadMike Oct 18 '13 at 6:46

You can use lsblk which prints partition information in a human friendly way, but can also change to use KEY=VALUE if you want to parse it.

Simply use

lsblk > name.txt

which will provide partition information to a file called name.txt in the current directory.

Example output of lsblk which is in name.txt:

sda           8:0    0 298.1G  0 disk 
├─sda1        8:1    0  97.7G  0 part 
├─sda2        8:2    0 134.1G  0 part 
├─sda3        8:3    0     1K  0 part 
├─sda5        8:5    0    57G  0 part /
└─sda6        8:6    0   9.3G  0 part [SWAP]
zram0       251:0    0 239.1M  0 disk [SWAP]
zram1       251:1    0 239.1M  0 disk [SWAP]
zram2       251:2    0 239.1M  0 disk [SWAP]
zram3       251:3    0 239.1M  0 disk [SWAP]

If you want a more machine friendly output, use the following command instead:

lsblk -bP -o NAME,SIZE,MOUNTPOINT > parseable.txt

which might produce (in parseable.txt). Sizes are in bytes because of the -b option.

NAME="sda" SIZE="320072933376" MOUNTPOINT=""
NAME="sda1" SIZE="104854820864" MOUNTPOINT=""
NAME="sda2" SIZE="144030984192" MOUNTPOINT=""
NAME="sda3" SIZE="1024" MOUNTPOINT=""
NAME="sda5" SIZE="61183361024" MOUNTPOINT="/"
NAME="sda6" SIZE="9999220736" MOUNTPOINT="[SWAP]"
NAME="zram0" SIZE="250691584" MOUNTPOINT="[SWAP]"
NAME="zram1" SIZE="250691584" MOUNTPOINT="[SWAP]"
NAME="zram2" SIZE="250691584" MOUNTPOINT="[SWAP]"
NAME="zram3" SIZE="250691584" MOUNTPOINT="[SWAP]"

In the case above, a mountpoint of "" indicates not mounted. You probably wont have as much zram as me (or maybe none at all).


I usually use this command to see partition size and usage:

df -h
  • 2
    The OP also asked how to add that info into a file named name.txt. – Seth Oct 17 '13 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.