Меню Рубрики

Linux show free space

Linux / Unix – Checking Free Disk Space

Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements None
Time 1m

(a) df command : Report file system disk space usage.

(b) du command : Estimate file space usage.

df command examples to check free disk space

Type df -h or df -k to list free disk space:
$ df -h
OR
$ df -k
Sample outputs that show disk space utilization:

The df utility displays statistics about the amount of free disk space on the specified file system or on the file system of which file is a part. Values are displayed in 512-byte per block counts. The -H option is called as “Human-readable” output. It use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 10 for sizes i.e. you see 30G (30 Gigabyte).

How to check free disk space in Linux

To see the file system’s complete disk usage pass the -a option:
df -a
Find out disk usage and filesystem type by passing the -T option:
df -T
Want to get used and free inodes information on Linux? Try:
df -i

du command examples for checking free and used disk space

The du command shows how much space one ore more files or directories is using, enter:
$ du -sh
Sample outputs:

Fig.01: Unix df and du command outputs from my FreeBSD server

Say hello to ncdu command

ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space. One can install with the following apt command/apt-get command:
sudo apt install ncdu
For RHEL/CentOS, first enable EPEL repo (see CentOS 8 turn on EPEL repo and RHEL 8 enable epel repo) and type the following yum command:
sudo yum install ncdu
Now just type:
ncdu
ncdu [dir] ncdu /etc/

GUI program

Above programs are good if GUI is not installed or you are working with remote system over the ssh based session. Linux and UNIX-like oses comes with KDE and Gnome desktop system. You will find Free Disk Space Applet located under GUI menus. Here is a sample from Fedora Linux version 22 system:

Conclusion

You learned how to keep track of disk utilization, and disk space with various Linux and Unix commands.

Источник

Get free disk space with df to just display free space in kb?

I’m trying to output the amount of free disk space on the filesystem /example .

If I run the command df -k /example I can get good information about available disk space in kb but only by being human and actually looking at it.

I need to take this data and use it somewhere else in my shell script. I initially thought about using cut but then my script wont be portable to other disks as free disk space will vary and cut will not produce accurate results.

How can I get output of just the free disk-space of example in kb?

4 Answers 4

To get the output of df to display the data in kb you just need to use the -k flag:

Also, if you specify a filesystem to df , you will get the values for that specific, instead of all of them:

Regarding the body of your question: you want to extract the amount of free disk space on a given filesystem. This will require some processing.

Given a normal df -k output:

You can get the Available (4th column) for example with awk or cut (previously piping to tr to squeeze-repeats ( -s ) for spaces):

As always, if you want to store the result in a variable, use the var=$(command) syntax like this:

Also, from the comment by Tim Bunce you can handle long filesystem names using —direct to get a — instead, so that it does not print a line that breaks the engine:

Источник

How to check free disk space in Linux

Keep track of disk utilization with this handy list of commands.

Subscribe now

Get the highlights in your inbox every week.

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.

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-ha.png

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-ti.png

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_space.jpg

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-has.png

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.

Источник

Check free disk space for current partition in bash

I am writing an installer in bash. The user will go to the target directory and runs the install script, so the first action should be to check that there is enough space. I know that df will report all file systems, but I was wondering if there was a way to get the free space just for the partition that the target directory is on.

Edit — the answer I came up with

Slightly odd because df seems to format its output to fit the terminal, so with a long mount point name the output is shifted down a line

7 Answers 7

for the current directory.

if you want to check a specific directory.

You might also want to check out the stat(1) command if your system has it. You can specify output formats to make it easier for your script to parse. Here’s a little example:

  1. df command : Report file system disk space usage
  2. du command : Estimate file space usage

Type df -h or df -k to list free disk space:

du shows how much space one or more files or directories is using:

The -s option summarizes the space a directory is using and -h option provides Human-readable output.

I think this should be a comment or an edit to ThinkingMedia’s answer on this very question (Check free disk space for current partition in bash), but I am not allowed to comment (not enough rep) and my edit has been rejected (reason: «this should be a comment or an answer»). So please, powers of the SO universe, don’t damn me for repeating and fixing someone else’s «answer». But someone on the internet was wrong!™ and they wouldn’t let me fix it.

has a substantial flaw: Yes, it will output 50G free as 50 — but it will also output 5.0M free as 50 or 3.4G free as 34 or 15K free as 15.

To create a script with the purpose of checking for a certain amount of free disk space you have to know the unit you’re checking against. Remove it (as sed does in the example above) the numbers don’t make sense anymore.

If you actually want it to work, you will have to do something like:

Also for an installer to df -k $INSTALL_TARGET_DIRECTORY might make more sense than df -k «$PWD» . Finally, please note that the —output flag is not available in every version of df / linux.

Источник

12 Useful “df” Commands to Check Disk Space in Linux

On the internet you will find plenty of tools for checking disk space utilization in Linux. However, Linux has a strong built-in utility called ‘df‘. The ‘df‘ command stands for “disk filesystem“, it is used to get a full summary of available and used disk space usage of the file system on Linux system.

Using ‘ -h ‘ parameter with (df -h) will show the file system disk space statistics in “human readable” format, means it gives the details in bytes, megabytes, and gigabyte.

Useful df Command Examples

This article explains a way to get the full information of Linux disk space usage with the help of ‘df‘ command with their practical examples. So, you could better understand the usage of df command in Linux.

1. Check File System Disk Space Usage

The “df” command displays the information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.

2. Display Information of all File System Disk Space Usage

The same as above, but it also displays information of dummy file systems along with all the file system disk usage and their memory utilization.

3. Show Disk Space Usage in Human Readable Format

Have you noticed that above commands displays information in bytes, which is not readable at all, because we are in a habit of reading the sizes in megabytes, gigabytes etc. as it makes very easy to understand and remember.

The df command provides an option to display sizes in Human Readable formats by using ‘-h’ (prints the results in human readable format (e.g., 1K 2M 3G)).

4. Display Information of /home File System

To see the information of only device /home file system in human readable format use the following command.

5. Display Information of File System in Bytes

To display all file system information and usage in 1024-byte blocks, use the option ‘ -k ‘ (e.g. —block-size=1K ) as follows.

6. Display Information of File System in MB

To display information of all file system usage in MB (Mega Byte) use the option as ‘ -m ‘.

7. Display Information of File System in GB

To display information of all file system statistics in GB (Gigabyte) use the option as ‘df -h‘.

8. Display File System Inodes

Using ‘ -i ‘ switch will display the information of number of used inodes and their percentage for the file system.

9. Display File System Type

If you notice all the above commands output, you will see there is no Linux file system type mentioned in the results. To check the file system type of your system use the option ‘ T ‘. It will display file system type along with other information.

10. Include Certain File System Type

If you want to display certain file system type use the ‘ -t ‘ option. For example, the following command will only display ext3 file system.

11. Exclude Certain File System Type

If you want to display file system type that doesn’t belongs to ext3 type use the option as ‘ -x ‘. For example, the following command will only display other file systems types other than ext3.

12. Display Information of df Command.

Using ‘—help ‘ switch will display a list of available option that is used with df command.

Read Also :

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Solidworks под mac os
  • Solidworks аналог для mac os
  • Solid edge mac os
  • Softwareupdated mac os процесс
  • Softube plugins mac os