[Python] 로컬디스크 체크

봉글렛·2022년 7월 6일
0

python

목록 보기
2/4
post-thumbnail

파이썬에서 로컬 디스크 체크하는 법.

우선 pip로 psutil를 인스톨 해주자

pip install psutil

그리고 disk_partitions를 사용하면 디스크 파티션에 대한 정보가 나온다.

psutil.disk_partitions()

disk_usage(path)를 사용하면 디스크의 총량, 사용량, 사용가능한양, 퍼센트가 나온다.

>>> psutil.disk_usage('/')
sdiskusage(total=499493838848, used=368182915072, free=131310923776, percent=73.7)

바이트(Byte)로 표기된다.
기가바이트(GB)로 바꿔보자.

import psutil

disk = psutil.disk_usage('/')
total = disk.total/(2**(10*3))
used = disk.used/(2**(10*3))
free = disk.free/(2**(10*3))
persent = disk.percent

print(total, used, free, persent, sep='\n')

결과

후기

psuil는 크롤링을 할때 디스크 공간을 관리하기위해 찾아본 모듈이다. psuil을 사용하면 disk뿐만아니라 실행 중인 프로세스, cpu, 메모리, 네트워크, 센서에 대한 정보를 가져올때 유용하게 쓸수 있다.

psuil pypi

profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글