본문 바로가기

UNIX/shell script

[UNIX] rm

rm -drf 디렉토리이름 (하위 디렉토리까지 싹 지움)
 
rm 이라는 명령으로 파일은 물론, 하위 디렉토리까지 지울 수 있습니다.

(RM 이라고 대문자로 하면 안됩니다. 반드시 소문자 rm 입니다. 리눅스/유닉스에서는 도스와 달리 대소문자를 구분합니다. 다만 Cygwin 은 파일명의 대소문자를 구분하지 않습니다.)

/usr/bin/
디렉토리 밑에 rm 이라는 파일이 있고 이것이 실행되는 것입니다.


rm --help 라고 하면 도움말이 나옵니다. 다음 화면은 윈도우에 Cygwin 을 깐 후, 윈도 명령 프롬프트에서 rm 을 실행시킨 결과입니다:

D:\Z>rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).

  -d, --directory       unlink FILE, even if it is a non-empty directory
                          (super-user only; this works only if your system
                           supports `unlink' for nonempty directories)
  -f, --force           ignore nonexistent files, never prompt
  -i, --interactive     prompt before any removal
      --no-preserve-root do not treat `/' specially (the default)
      --preserve-root   fail to operate recursively on `/'
  -r, -R, --recursive   remove directories and their contents recursively
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it is usually possible to recover
the contents of that file.  If you want more assurance that the contents are
truly unrecoverable, consider using shred.

Report bugs to <bug-coreutils@gnu.org>.

D:\Z>

* unlink : 파일이나 디렉토리를 지운다는 의미



옵션 설명


-d : 비어 있지 않은 디렉토리도 지움
-f : 존재하지 않거나 이미 지워진 파일은 무시하고 다음으로 조용히 넘어감
-i : 지우기 전에 "rm: remove regular file `test.txt'? (test.txt 파일을 지울까요?)" 하고 물어보게 함
-r : 하위 디렉토리까지 모두 지우기
-v : 무엇을 지웠는지 보고하게 함. ("removed `test.txt'" 라는 메시지가 나옴)