rm 명령어 (AIX 5.3·6.1)

핵심 정리

  • 디렉터리에서 파일 항목을 지웁니다(unlink). 그 항목이 파일의 마지막 링크면 파일 자체가 지워집니다.
  • 파일 자체의 읽기·쓰기 권한은 필요 없고, 파일이 든 디렉터리의 쓰기 권한이 필요합니다.
  • 쓰기 권한이 없는 파일은 표준 입력이 터미널일 때 지울지 묻습니다. -f는 묻지 않고, 없는 파일에 대한 오류도 내지 않습니다.
  • -i는 파일마다 묻고, -r·-R은 디렉터리를 내용까지 재귀적으로 지웁니다. -e는 지울 때마다 메시지를 냅니다.
  • 심볼릭 링크는 링크만 지우고 가리키는 대상은 남깁니다. .과 ..은 지우지 않습니다.
  • 스티키 비트가 켜진 남의 디렉터리에서는 다른 사용자의 파일을 지울 수 없습니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (내용 같음, 6.1에 보안 절이 더해짐)
원문 IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4
파일 /usr/bin/rm
관련 명령어 ln, unlink, rmdir

목적

파일이나 디렉터리를 지웁니다(링크를 끊습니다).

영어 원문

Removes (unlinks) files or directories.

구문

text
rm [ -f ] [ -r ] [ -R ] [ -i ] [ -e ] File ...

설명

rm 명령은 지정한 File 매개변수의 항목을 디렉터리에서 지웁니다. 그 항목이 파일의 마지막 링크면 파일이 지워집니다.

파일에 쓰기 권한이 없고 표준 입력이 터미널이면, 파일 이름을 보여 주며 지울지 확인을 받습니다. y(yes)를 입력하면 지우고, 다른 문자를 입력하면 지우지 않습니다.

지울 파일의 읽기·쓰기 권한은 필요 없습니다. 하지만 파일이 든 디렉터리의 쓰기 권한은 있어야 합니다.

파일이 심볼릭 링크면 링크를 지우고, 링크가 가리키는 파일이나 디렉터리는 남깁니다. 디렉터리에 쓰기 권한이 있으면 심볼릭 링크를 지우는 데 링크의 쓰기 권한은 필요 없습니다.

File 매개변수의 기본 이름 부분이 .(점)이나 ..(점 두 개)면, 표준 오류에 진단 메시지를 쓰고 그 매개변수는 더 처리하지 않습니다.

-f 플래그가 없고, File에 쓰기 권한이 없으며 표준 입력이 워크스테이션(터미널)이거나 -i 플래그를 지정했으면, 표준 오류에 질문을 쓰고 표준 입력에서 한 줄을 읽습니다. 긍정하는 답이 아니면 그 파일은 그대로 두고 다음 파일로 넘어갑니다.

디렉터리에 스티키 비트가 켜져 있고 그 디렉터리를 사용자가 소유하지 않으면, 다른 사용자가 소유한 파일은 지울 수 없습니다.

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

NFS 버전 4 서버용으로 내보낸 파일이나 디렉터리를 지우려 하면 자원이 사용 중이라는 메시지와 함께 실패합니다. 지우려면 먼저 NFS 버전 4 내보내기를 해제해야 합니다.

영어 원문

The rm command removes the entries for the specified File parameter from a directory. If an entry is the last link to a file, the file is then deleted. If you do not have write permission for a file and the standard input is a terminal, you are prompted with the file name and ask to confirm that you want to delete the file. If you type a y (for yes), the file is deleted, type any other character and the file is not deleted. You do not need read or write permission for the file you want to remove. However, you must have write permission for the directory containing the file.

If the file is a symbolic link, the link is removed, but the file or directory that the symbolic link refers to remains. You do not need write permission to delete a symbolic link, if you have write permission in the directory.

If either of the files . (dot) or .. (dot, dot) are specified as the base name portion of the File parameter, the rm command writes a diagnostic message to standard error and does nothing more with such parameters.

The rm command writes a prompt to standard error and reads a line from standard input if the -f flag is not specified, and either the File parameter does not have write permission and the standard input is a workstation, or the -i flag is specified. If the response is not affirmative, the rm command does nothing more with the current file and proceeds to the next file.

The files owned by other users cannot be removed if the sticky bit of the directory is set and the directory is not owned by the user.

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

An attempt to remove a file or directory that has been exported for use by the NFS version 4 server will fail with a message saying that the resource is busy. The file or directory must be unexported for NFS version 4 use before it can be removed.

플래그

플래그 설명
-e 파일을 지울 때마다 메시지를 표시합니다.
-f 쓰기 보호된 파일을 지우기 전에 묻지 않습니다. 지정한 파일이 없어도 오류 메시지를 내거나 오류 상태를 돌려주지 않습니다. -f와 -i를 함께 지정하면 마지막 것이 적용됩니다.
-i 파일을 지우기 전마다 묻습니다. -i와 -r을 함께 쓰면 디렉터리를 지우기 전에도 묻습니다. -i와 -f를 함께 지정하면 마지막 것이 적용됩니다.
-r File 매개변수가 디렉터리면 디렉터리와 그 내용을 재귀적으로 지울 수 있게 합니다. -R과 같습니다.
-R File 매개변수가 디렉터리면 디렉터리와 그 내용을 재귀적으로 지울 수 있게 합니다. -r과 같습니다.
영어 원문
  • -e — Displays a message after each file is deleted.
  • -f — Does not prompt before removing a write-protected file. Does not display an error message or return error status if a specified file does not exist. If both the -f and -i flags are specified, the last one specified takes affect.
  • -i — Prompts you before deleting each file. When you use the -i and -r flags together, the rm command also prompts before deleting directories. If both the -i and -f flags are specified, the last one specified takes affect.
  • -r — Permits recursive removal of directories and their contents when the File parameter is a directory. This flag is equivalent to the -R flag.
  • -R — Permits recursive removal of directories and their contents when the File parameter is a directory. This flag is equivalent to the -r flag.

종료 상태

값 뜻
0 -f를 지정하지 않았으면 지정한 디렉터리 항목을 모두 지웠고, -f를 지정했으면 지정한 항목 중 있는 것을 모두 지웠습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — If the -f flag was not specified, all the named directory entries were removed; otherwise, all the existing named directory entries were removed.
  • >0 — An error occurred.

보안

RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 이 명령에 걸린 특권과 권한(authorization) 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다. 이 절은 6.1 문서에만 있습니다.

영어 원문

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

예제

  1. 파일을 지웁니다. 이 파일에 다른 링크가 있으면 파일은 그 이름으로 남고 myfile이라는 이름만 없어집니다. myfile이 유일한 링크면 파일 자체가 지워집니다.
bash
rm myfile
  1. 확인 질문 없이 파일을 지웁니다. core 파일을 지우기 전에 묻지 않습니다. 하지만 core가 쓰기 보호돼 있고, 파일 소유자가 아니거나 root 권한이 없으면 오류 메시지가 나옵니다. 없는 파일을 지우려 할 때는 오류 메시지가 나오지 않습니다.
bash
rm -f core
  1. 파일을 하나씩 확인하며 지웁니다. 파일 이름이 나올 때마다 y를 입력하면 지우고, Enter 키를 누르면 남깁니다.
bash
rm -i mydir/*
  1. 디렉터리 트리를 지웁니다. manual 디렉터리의 모든 하위 디렉터리 내용을 파일마다 물어보며 재귀적으로 지운 뒤, manual 디렉터리 자체를 지웁니다.
text
사용자: rm -ir manual
시스템: rm: Select files in directory manual? Enter y for yes.
사용자: y
시스템: rm: Select files in directory manual/draft1? Enter y for yes.
사용자: y
시스템: rm: Remove manual/draft1?
사용자: y
시스템: rm: Remove manual/draft1/chapter1?
사용자: y
시스템: rm: Remove manual/draft1/chapter2?
사용자: y
시스템: rm: Select files in directory manual/draft2? Enter y for yes.
사용자: y
시스템: rm: Remove manual/draft2?
사용자: y
시스템: rm: Remove manual?
사용자: y

먼저 manual 디렉터리를 검색할지 묻습니다. manual에 디렉터리가 있으므로 다음으로 manual/draft1을 검색할지 묻고, manual/draft1/chapter1과 manual/draft1/chapter2를 지울지 묻습니다. 이어서 manual/draft2 디렉터리를 검색할지 묻고, manual/draft1, manual/draft2, manual 디렉터리를 지울지 묻습니다. 하위 디렉터리(예: manual/draft2)를 지우지 않겠다고 답하면 manual 디렉터리도 지우지 않고 rm: Directory manual not empty 메시지를 보여 줍니다.

영어 원문
  1. To delete a file, enter: rm myfile

If there is another link to this file, then the file remains under that name, but the name myfile is removed. If myfile is the only link, the file itself is deleted.

  1. To delete a file without first receiving a confirmation prompt, enter:

rm -f core

No confirmation prompt is issued before the rm -f command attempts to remove the file named core. However, an error message displays if the core file is write-protected and you are not the owner of the file or you do not have root authority. No error message displays when the rm -f command attempts to remove nonexistent files.

  1. To delete files one by one, enter:

rm -i mydir/*

After each file name is displayed, enter y to delete the file, or press the Enter key to keep it.

  1. To delete a directory tree, enter: rm -ir manual

This command recursively removes the contents of all subdirectories of the manual directory, prompting you regarding the removal of each file, and then removes the manual directory itself, for example:

You: rm -ir manual
System: rm: Select files in directory manual? Enter y for yes.
You: y
System: rm: Select files in directory manual/draft1? Enter y for yes.
You: y
System: rm: Remove manual/draft1?
You: y
System: rm: Remove manual/draft1/chapter1?
You: y
System: rm: Remove manual/draft1/chapter2?
You: y
System: rm: Select files in directory manual/draft2? Enter y for yes.
You: y
System: rm: Remove manual/draft2?
You: y
System: rm: Remove manual?
You: y

Here, the rm command first asks if you want it to search the manual directory. Because the manual directory contains directories, the rm command next asks for permission to search manual/draft1 for files to delete, and then asks if you want it to delete the manual/draft1/chapter1 and manual/draft1/chapter2 files. The rm command next asks for permission to search the manual/draft2 directory. Then asks for permission to delete the manual/draft1, manual/draft2, and manual directories. If you deny permission to remove a subdirectory (for example, manual/draft2), the rm command does not remove the manual directory. Instead, you see the message: rm: Directory manual not empty.

파일

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

관련 명령어: ln, unlink

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

Related information:

  • ln command
  • unlink command
  • Directories command
  • File and directory access modes
  • File and directory links

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU rm
-e 지울 때마다 메시지 표시 없음(-v가 비슷함)
-r -i 디렉터리마다 "검색할지"와 "지울지"를 따로 물음 디렉터리에 들어갈지, 지울지를 물음
NFS4 내보낸 객체 사용 중이라며 지우지 않음 해당 없음

AIX 5.3·6.1 문서에는 -v, -I(한 번만 묻기), --preserve-root, -d(빈 디렉터리 지우기) 같은 GNU 플래그가 없습니다.