rmdir 명령어 (AIX 5.3·6.1)

핵심 정리

  • 빈 디렉터리를 지웁니다. 부모 디렉터리에 쓰기 권한이 있어야 합니다.
  • 디렉터리가 비었는지는 ls -al로 확인합니다. 점으로 시작하는 파일이 남아 있으면 지워지지 않습니다.
  • -p는 경로를 따라 상위 디렉터리까지 차례로 지웁니다. 도중에 비지 않았거나 쓰기 권한이 없는 디렉터리를 만나면 멈춥니다.
  • NFS 버전 4 서버용으로 내보낸 디렉터리는 지울 수 없습니다.
  • 내용까지 지우려면 rm -r을 씁니다.
  • AIX 5.3과 6.1 문서의 내용이 같습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (두 버전 내용 같음)
원문 IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4
파일 /usr/bin/rmdir
관련 명령어 rm, ls, mkdir, unlink

목적

디렉터리를 지웁니다.

영어 원문

Removes a directory.

구문

text
rmdir [ -p ] Directory ...

설명

rmdir 명령은 Directory 매개변수로 지정한 디렉터리를 시스템에서 지웁니다. 지우려면 디렉터리가 비어 있어야 하고, 부모 디렉터리에 쓰기 권한이 있어야 합니다. 디렉터리가 비었는지는 ls -al 명령으로 확인합니다. 디렉터리를 NFS 버전 4 서버용으로 내보낸 상태면 안 됩니다.

참고: rmdir 명령은 플래그의 끝을 나타내는 구분자로 --(대시 두 개) 매개변수를 지원합니다.

영어 원문

The rmdir command removes the directory, specified by the Directory parameter, from the system. The directory must be empty before you can remove it, and you must have write permission in its parent directory. Use the ls -al command to check whether the directory is empty. The directory must not be exported for use by the NFS version 4 server.

Note: The rmdir command supports the — (dash, dash) parameter as a delimiter that indicates the end of the flags.

플래그

플래그 설명
-p Directory Directory 매개변수로 지정한 경로를 따라 디렉터리를 모두 지웁니다. 부모 디렉터리도 비어 있어야 하고, 사용자에게 그 부모 디렉터리의 쓰기 권한이 있어야 지울 수 있습니다.
영어 원문
  • -pDirectory — Removes all directories along the path name specified by the Directory parameter. Parent directories must be empty and the user must have write permission in the parent directories before they can be removed.

종료 상태

값 뜻
0 Directory 매개변수로 지정한 디렉터리 항목을 모두 지웠습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — Each directory entry specified by a Directory parameter was removed successfully.
  • >0 — An error occurred.

예제

  1. 디렉터리를 비운 뒤 지웁니다.
bash
rm mydir/* mydir/.*
rmdir mydir

mydir의 내용을 지운 뒤 빈 디렉터리를 지웁니다. rm 명령은 .(점)과 ..(점 두 개) 디렉터리를 지우려 했다는 오류 메시지를 보여 주고, 그다음 rmdir 명령이 디렉터리를 지웁니다.

rm mydir/* mydir/.*는 먼저 점으로 시작하지 않는 파일을 지우고, 다음으로 점으로 시작하는 파일을 지웁니다. ls 명령은 -a 플래그를 주지 않으면 점으로 시작하는 파일을 보여 주지 않으므로, 그런 파일이 있다는 것을 모르고 지나치기 쉽습니다.

  1. /home, /home/demo, /home/demo/mydir 디렉터리를 지웁니다. 먼저 mydir을, 다음으로 demo와 home을 차례로 지웁니다. 지울 차례의 디렉터리가 비어 있지 않거나 쓰기 권한이 없으면 명령이 멈춥니다.
bash
rmdir -p /home/demo/mydir
영어 원문
  1. To empty and remove a directory, type:
rm mydir/* mydir/.*
rmdir mydir

This command removes the contents of the mydir file and then removes the empty directory. The rm command displays an error message about trying to remove the directories . (dot) and .. (dot, dot), and then the rmdir command removes them.

Note that the rm mydir/* mydir/.* command first removes files with names that do not begin with a dot, and then removes those with names that do begin with a dot. You may not realize that the directory contains file names that begin with a dot because the ls command does not usually list them unless you use the -a flag.

  1. To remove the /home, /home/demo, and /home/demo/mydir directories, type: rmdir -p /home/demo/mydir

This command removes first the /mydir directory and then the /demo and /home directories, respectively. If a directory is not empty or does not have write permission when it is to be removed, the command terminates.

파일

파일 설명
/usr/bin/rmdir rmdir 명령이 들어 있습니다.

관련 명령어: ls, mkdir, unlink

영어 원문
  • /usr/bin/rmdir — Contains the rmdir command.

Related information:

  • Files command
  • Directories command
  • ls command
  • mkdir command
  • unlink command

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU rmdir
NFS4 내보낸 디렉터리 지울 수 없다고 명시 해당 없음

AIX 5.3·6.1 문서에는 --ignore-fail-on-non-empty, -v 같은 GNU 플래그가 없습니다.