리눅스 폴더만 삭제

Jmnote (토론 | 기여)님의 2013년 6월 28일 (금) 20:02 판
How to remove folders only in linux
리눅스 폴더만 삭제

1 명령어

현재폴더에서 하위 폴더 삭제
ll | grep ^d | awk '{print $NF}' | xargs rm -rf
특정폴더에서 하위 폴더 삭제
ll /폴더/경로/ | grep ^d | awk '{print $NF}' | xargs rm -rf

2 실행예시

[root@jmnote test]# ll
total 16
-rw-r--r-- 1 root root    6 Jun 28 15:35 file1.txt
-rw-r--r-- 1 root root    6 Jun 28 15:36 file2.txt
drwxr-xr-x 2 root root 4096 Jun 28 15:36 folder1
drwxr-xr-x 2 root root 4096 Jun 28 15:36 folder2
[root@jmnote test]# ll | grep ^d | awk '{print $NF}' | xargs rm -rf
[root@jmnote test]# ll
total 8
-rw-r--r-- 1 root root 6 Jun 28 15:35 file1.txt
-rw-r--r-- 1 root root 6 Jun 28 15:36 file2.txt
→ 폴더는 삭제되고 파일만 남았다.

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}