Open In App

Python | shutil.disk_usage() method

Last Updated : 20 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 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)


Output:

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)


Output:

usage(total=209190907904, used=92728918016, free=116461989888)


Previous Article
Next Article

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 :