컴퓨터 엑셀 워드 포토샵 구글어스 WINDOWS JAVASCRIPT JAVA C++

 
Saturday, July 15, 2006

리눅스/Cygwin] 파일/디렉토리 지우는 명령어, 파일 삭제: rm


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'" 라는 메시지가 나옴)

rm 은, 도스의 del 명령보다 훨씬 더 강력하기 때문에, 아주 위험한 명령입니다. 실은 제가 어제 rm 명령을 배치 파일* 안에서 사용하다가 하드 전체를 날릴 뻔했습니다. Cygwin의 rm 과, GnuWin32의 rm 은, 디렉토리 경로를 해석하는 부분에 미묘한 차이가 있는 듯한데 그런 이유에서였습니다.


* Cygwin에서는 윈도의 배치 파일도 실행됨. 단, .bat 이라는 확장자까지 붙여 주어야 함.





또한 unlink 명령으로도 파일을 지울 수 있습니다.



▶▶ 리눅스] 디렉토리 만들기 명령, 디렉토리(폴더) 지우기 명령어: Make, Delete Directory

☞ 리눅스(Linux)/유닉스(Unix)/시그윈(Cygwin)

0 Comments:

Post a Comment

<< Home RSS 2.0 feed

구글 Google 에서 제공하는 무료 블로그 서비스인 블로거 Blogger 의 인터넷 주소는 www.blogger.com 입니다. Blogger 에 블로그를 만들면, blogspot.com 이라는 주소에 블로그가 생성됩니다.
블로그를 직접 방문하지 않고도 최신 게시물을 구독하려면 RSS 2.0 feed 주소를 리더기에 등록하시면 됩니다.
Previous Posts
Monthly Archives
Top