붉은거위 노트 (redgoose note)

특정 디렉토리 하위에서 node_modules 디렉토리 전부 삭제하기

Nest
ETC
Category
MacOS
Hit
140
Star
0

node_modules 디렉토리는 많은 파일과 디렉토리들이 들어있어서 백업하는데 많이 방해될 것이다.

예제 경로는 ~/dev 하위에 있는 모든 node_modules 디렉토리를 삭제하는것이다.

먼저 다음과 같이 디렉토리가 어디에 있는지 확인하자.

find ~/dev -name "node_modules" -type d -prune -print | xargs du -chs

이렇게 실행하면 다음과 같이 경로와 용량이 표시된다.

 65M	./toy/rive/node_modules
 31M	./toy/custom-components/node_modules
 31M	./toy/event-pages/node_modules
 31M	./toy/image-draw/node_modules
5.0G	total

확인하고나서 확실히 지우고 싶으면 다음과 같이 실행하면 한번에 다 지워진다.
이 명령어로 실행하면 복구할 수 없으므로 주의하자!

find ~/dev -name "node_modules" -type d -prune -print -exec rm -rf '{}' +

# from current directory
find . -name "node_modules" -type d -prune -print -exec rm -rf '{}' +