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 tells the disk usage statistics about the given path as a named tuple with the attributes total, used and free where total represents total amount of memory, used represents used memory and free represents free memory.
Note: All the memory values are in bytes.
Syntax: shutil.disk_usage(path)
Parameter:
path: A string representing the path.Return Value: This method returns a named tuple with the attributes total, used and free which are the amount of total, used and free space, in bytes
Example #1 :
Using shutil.disk_usage() method to know about memory usage statistics of GeeksforGeeks server.
# Python program to explain shutil.disk_usage() method # importing os module import os # importing shutil module import shutil # path # As the path for GFG is root so '/' is used path = '/' # Using shutil.disk_usage() method memory = shutil.disk_usage(path) # Print result print(memory) |
usage(total=51976970240, used=27151167488, free=24809025536)
Example #2 :
Using shutil.disk_usage() method to know about memory usage statistics of any user Computer.
# Python program to explain shutil.disk_usage() method # importing os module import os # importing shutil module import shutil # path path = 'C:/Users/User_name/GeeksforGeeks' # Using shutil.disk_usage() method memory = shutil.disk_usage(path) # Print result print(memory) |
usage(total=209190907904, used=92728918016, free=116461989888)
Recommended Posts:
- class method vs static method in Python
- Difference between Method Overloading and Method Overriding in Python
- Get() method for dictionaries in Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Line detection in python with OpenCV | Houghline method
- Python | os._exit() method
- Python | os.WEXITSTATUS() method
- Python | os.abort() method
- Python | os.renames() method
- Python | os.lseek() method
- Python calendar module | formatmonth() method
- Python | PyTorch sin() method
- Python | Sympy Line.is_parallel() method
- Python PIL | GaussianBlur() method
- Python | range() method
- Python | Numpy np.hermefit() method
- Python | Numpy np.hermevander() method
- Python String Title method
- Python groupby method to remove all consecutive duplicates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

