The Wayback Machine - https://web.archive.org/web/20240614141133/https://www.geeksforgeeks.org/python-shutil-disk_usage-method/
Open In App

Python | shutil.disk_usage() method

Last Updated : 07 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories.

shutil.disk_usage() method in Python is to get disk usage statistics about the given path. This method returns a named tuple with attributes total, used and free. The total attribute represents the amount of total space, the used attribute represents the amount of used space and the free attribute represents the amount of available space, in bytes.

Note: On Windows, the given path must represent a directory but on Unix systems, it can be a file or directory.

Syntax: shutil.disk_usage(path)

Parameter:
path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path.

Return Type: This method returns a named tuple with attributed total, used and free.

Code: Use of shutil.disk_usage() method




# Python program to explain shutil.disk_usage() method 
    
# importing shutil module 
import shutil
  
# Path
path = "/home/User/Documents"
  
# Get the disk usage statistics
# about the given path
stat = shutil.disk_usage(path)
  
# Print disk usage statistics
print("Disk usage statistics:")
print(stat)


Output:

Disk usage statistics:
usage(total=244934381568, used=13350301696, free=219070689280)

Reference: https://docs.python.org/3/library/shutil.html


Similar Reads

Python | shutil.get_archive_formats() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories. shutil.get_archive_formats() method in Python is used to get the list of supported formats for archivin
1 min read
Python | shutil.copy() method
C/C++ Code # Python program to explain shutil.copy() method # importing shutil module import shutil # Source path source = "/home/User/Documents/file.txt" # Destination path destination = "/home/User/Documents/file.txt" # Copy the content of # source to destination try: shutil.copy(source, destination) print("File copied su
5 min read
Python | shutil.copy2() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories.shutil.copy2() method in Python is used to copy the content of source file to destination file or direct
4 min read
Python | shutil.get_unpack_formats() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories. shutil.get_unpack_formats() method in Python is used to get the list of all supported formats available
2 min read
Python | shutil.unregister_unpack_format() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories. shutil.unregister_unpack_format() method in Python is used to unregister or remove an unpack format fro
2 min read
Python | shutil.unregister_archive_format() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories. shutil.unregister_archive_format() method in Python is used to unregister or remove an archive form
2 min read
Python | shutil.copystat() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories.shutil.copystat() method in Python is used to copy the permission bits, last access time, last modificat
3 min read
Python | shutil.copymode() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories.shutil.copymode() method in Python is used to copy the permission bits from the given source path to
2 min read
Python | shutil.move() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories. shutil.move() method Recursively moves a file or directory (source) to another location (destinatio
2 min read
Python | shutil.copytree() method
Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories. shutil.copytree() method recursively copies an entire directory tree rooted at source (src) to the dest
3 min read
Article Tags :
Practice Tags :