Space on hdd linux

How to view unallocated free space on a hard disk through terminal [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

I want to view the unallocated free space on my hard disk through terminal. I’ve burned my brains searching the internet for a possible solution, but all in vain. I used all sorts of commands like df , du , fdisk , parted , etc. It tells me about the disks that are mounted and unmounted, but what about the unallocated space that I’ve left free? Of course I can view it using the ‘Disk Utility’ app provided by Fedora, but since I LOVE being in the terminal I’d like to view in it. Can anyone please help me with a solution?

You might have a misunderstanding about free space. Don’t forget overhead, and do remember that open(2) -ed but unlink(2) -ed files still use disk space.

This may be considered off-topic for Stack Overflow. You might want to ask about this on Unix.SE or Super User (but search for it there first!).

13 Answers 13

Use GNU parted and print free command:

root@sandbox:~# parted GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print free Model: VMware Virtual disk (scsi) Disk /dev/sda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 256MB 255MB primary ext2 boot 256MB 257MB 1048kB Free Space 2 257MB 64.4GB 64.2GB extended 5 257MB 64.4GB 64.2GB logical lvm 64.4GB 64.4GB 1049kB Free Space 

The command to use/reclaim that free space depends on where that free space is located, between existing partitions, and what kind of partitions you have (primary, extended) and also if you use LVM or not. It’s not trivial to just run a simple command that will read your mind and know what you want to actually do with that free space 🙂

Читайте также:  Apache on linux or windows

# parted /dev/sda unit TB print free | grep ‘Free Space’ | tail -n1 | awk »

# parted /dev/sda unit GB print free | grep ‘Free Space’ | tail -n1 | awk »

# parted /dev/sda unit MB print free | grep ‘Free Space’ | tail -n1 | awk »

# parted /dev/sda unit B print free | grep ‘Free Space’ | tail -n1 | awk »

# parted /dev/sda unit ‘%’ print free | grep ‘Free Space’ | tail -n1 | awk »

# parted /dev/sda unit s print free | grep ‘Free Space’ | tail -n1 | awk »

Change /dev/sda to whatever device you are trying to find the information about. If you are using the result in any calculations, make sure to trim the trailing characters.

By adding the —machine argument to the parted invocation, you get colon separated output which will be much more reliable to parse than the default human readable output.

With the parted commands like this, parted will run in interactive mode. If this isn’t intended, the «unit TB» and «print free» commands need to swap places. This is also how the —help option shows it: first the command, then command args. The full command would then be: parted /dev/sda print free unit TB

The simplest way to show unallocated free space in a single command:

$ sudo sfdisk --list-free /dev/sdX 

(Add the —quiet option if you don’t need the extra info about sector size, etc.)

In addition to all the answers about how to find unpartitioned space, you may also have space allocated to an LVM volume but not actually in use. You can list physical volumes with the pvdisplay and see which volume groups each physical volume is associated with. If a physical volume isn’t associated with any volume group, it’s safe to reallocate or destroy. Assuming that it it is associated with a volume group, the next step is to use vgdisplay to show your those. Among other things, this will show if you have any free «physical extents» — blocks of storage you can assign to a logical volume. You can get this in a concise form with vgs :

$ sudo vgs VG #PV #LV #SN Attr VSize VFree fedora 1 3 0 wz--n- 237.46g 0 

. and here you can see I have nothing free. If I did, that last number would be bigger than zero.

This is important, because that free space is invisible to du , df , and the like, and also will show up as an allocated partition if you are using fdisk or another partitioning tool.

Читайте также:  Добавить путь переменную path linux

vgdisplay really was the answer for me, as with most installers today a great option is to go with encrypted LVM which creates volume groups with logical volumes within. Then when moving space around the unallocated space is in the volume group, not the physical volume partitions.

I had just the same trouble with fedora 26 and LVM partitions, it seems I forgot check something during the installation, So, my 15G root directory has been increased to 227G like I needed.

I posted the steps I followed here:

0) #df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 824K 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/fedora-root 15G 2.1G 13G 14% / tmpfs 1.9G 0 1.9G 0% /tmp /dev/md126p1 976M 119M 790M 14% /boot tmpfs 388M 0 388M 0% /run/user/0 1) # vgs VG #PV #LV #SN Attr VSize VFree fedora 1 2 0 wz--n- 231.88g 212.96g 2) # vgdisplay --- Volume group --- VG Name fedora System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 231.88 GiB PE Size 4.00 MiB Total PE 59361 Alloc PE / Size 4844 / 18.92 GiB Free PE / Size 54517 / 212.96 GiB VG UUID 9htamV-DveQ-Jiht-Yfth-OZp7-XUDC-tWh5Lv 3) # lvextend -l +100%FREE /dev/mapper/fedora-root Size of logical volume fedora/root changed from 15.00 GiB (3840 extents) to 227.96 GiB (58357 extents). Logical volume fedora/root successfully resized. 4) #lvdisplay 5) #fd -h 6) # xfs_growfs /dev/mapper/fedora-root meta-data=/dev/mapper/fedora-root isize=512 agcount=4, agsize=983040 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1 spinodes=0 rmapbt=0 = reflink=0 data = bsize=4096 blocks=3932160, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 3932160 to 59757568 7) #df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 828K 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/mapper/fedora-root 228G 2.3G 226G 2% / tmpfs 1.9G 0 1.9G 0% /tmp /dev/md126p1 976M 119M 790M 14% /boot tmpfs 388M 0 388M 0% /run/user/0 

Источник

5 Linux commands to check free disk space

How to find files in Linux

Keeping track of disk utilization information is on system administrators’ (and others’) daily to-do list. Linux has a few built-in utilities that help provide that information.

Читайте также:  Cr2 to jpg linux

Linux df command

The df command stands for «disk-free,» and shows available and used disk space on the Linux system.

df -h shows disk space in human-readable format

df -a shows the file system’s complete disk usage even if the Available field is 0

df command

df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)

df -i shows used and free inodes

df command

You can get this information in a graphical view using the Disks (gnome-disk-utility) in the GNOME desktop. Launch it to see all disks detected by your computer, and click a partition to see details about it, including space used and space remaining.

GNOME Disks

Linux du command

du shows the disk usage of files, folders, etc. in the default kilobyte size

du -h shows disk usage in human-readable format for all directories and subdirectories

du -a shows disk usage for all files

du -s provides total disk space used by a particular file or directory

du command

The following commands will check your total space and your utilized space.

This information can be represented visually in GNOME with the Disk Usage application, or with Filelight in the KDE Plasma desktop. In both applications, disk usage is mapped to concentric circles, with the middle being the base folder (usually your /home directory, but it’s up to you) with each outer ring representing one directory level deeper. Roll your mouse over any segment for detailed information about what’s taking up space.

Disk usage

Linux ls -al command

ls -al lists the entire contents, along with their size, of a particular directory

ls -al command

Linux stat command

stat displays the size and other stats of a file/directory or a filesystem.

stat command

Linux fdisk -l command

fdisk -l shows disk size along with disk partitioning information

fdisk - l command

These are most of the built-in utilities for checking file space in Linux. There are many similar tools, like Disks (GUI), Ncdu, etc., that also show disk space utilization. Do you have a favorite tool that’s not on this list? Please share in the comments.

This article was originally published in July 2018 and has been updated to include additional information.

Check disk usage

Check used disk space on Linux with du

Find out how much disk space you’re using with the Linux du command.

Free disk space

Use df to check free disk space on Linux

Find out how much Linux disk space you have left with the df command.

Источник

Оцените статью
Adblock
detector