Mac rmdir 강제 삭제 - Mac rmdir gangje sagje

rm 커맨드를 활용하여 파일 또는 폴더를 지우는 방법입니다. 옵션 및 Description을 하나하나씩 다 파헤쳐보는 것은 분명 도움이 되겠지만, 사실 큰 의미 없이 마구잡이로 사용하고 있는 커맨드입니다.

‘man rm’로 매뉴얼을 읽어보면, ‘non-directory type files’라고 ‘디렉토리가 아닌 파일들을 지운다’라고 되어있지만.. 디렉토리 타입도 지울 수 있습니다.


rm Syntax

아래와 같은 문법을 사용합니다. 일반 파일을 삭제하실 때는 ‘rm [파일이름]’만 사용하셔도 충분합니다.

$ rm [option] filename

예시

아래 예시를 보시면 많이 쓰이는 옵션으로 크게 세가지로 구분할 수 있습니다. 플래그들은 커맨드가 다르더라도 같은 알파벳에 같은 기능을 하는 것이 대부분입니다. 몇번 써보다 보면, 금방 외워서 사용할 수 있습니다.

  • -f : 쓰기권한(수정, 추가 삭제)이 없더라도, 묻지말고 지우기
  • -i : 물어보고 지우기 (-I : 여러파일을 지울땐 한번만 물어보기)
  • -r : 디렉토리 및 그 안의 모든 파일 지우기(reculsive의 약자)
$rm text.txt
// text.txt 파일 지우기.

$rm -f text.txt
// text.txt 파일을 묻지 않고 지우기.

$rm *
// 현재 작업중이 directory의 모든 파일 지우기.

$rm -*
// 묻지도 따지지도 않고 다 지우기.

rm -*
//파일 하나하나 물어보고 지우기.

rm -*
//전체 파일 한번만 물어보고 다 지우기.

rm -r directory1
// directory1 폴더 및 안의 파일 다 지우기.

rm -rf directory1
// 묻지도 따지지도 않고 다 지우기. (-f 옵션 + -r 옵션)

  • 실사용 예 ▼
Mac rmdir 강제 삭제 - Mac rmdir gangje sagje
terminal rm
  • 주의 ▼

만약, 파일이름이 ‘-text.txt’와 같이 -로 시작한다면, 지우기 전에 ‘–‘를 아래와 같이 명시해주셔야 합니다. ‘-‘ dash는 원래 옵션을 명시하는 문법으로써, ‘-text.txt’가 옵션이 아니라는 걸 정확하게 알려주어야 합니다.

rm -- -text.txt
  • man rm 참조 ▼
DESCRIPTION
     The rm utility attempts to remove the non-directory type files specified
     on the command line.  If the permissions of the file do not permit writ-
     ing, and the standard input device is a terminal, the user is prompted
     (on the standard error output) for confirmation.

     The options are as follows:

     -d          Attempt to remove directories as well as other types of
                 files.

     -f          Attempt to remove the files without prompting for confirma-
                 tion, regardless of the file's permissions.  If the file does
                 not exist, do not display a diagnostic message or modify the
                 exit status to reflect an error.  The -f option overrides any
                 previous -i options.

     -i          Request confirmation before attempting to remove each file,
                 regardless of the file's permissions, or whether or not the
                 standard input device is a terminal.  The -i option overrides
                 any previous -f options.

     -P          Overwrite regular files before deleting them.  Files are
                 overwritten three times, first with the byte pattern 0xff,
                 then 0x00, and then 0xff again, before they are deleted.

     -R          Attempt to remove the file hierarchy rooted in each file
                 argument.  The -R option implies the -d option.  If the -i
                 option is specified, the user is prompted for confirmation
                 before each directory's contents are processed (as well as
                 before the attempt is made to remove the directory).  If the
                 user does not respond affirmatively, the file hierarchy
                 rooted in that directory is skipped.

     -r          Equivalent to -R.
     -P          Overwrite regular files before deleting them.  Files are
                 overwritten three times, first with the byte pattern 0xff,
                 then 0x00, and then 0xff again, before they are deleted.

     -R          Attempt to remove the file hierarchy rooted in each file
                 argument.  The -R option implies the -d option.  If the -i
                 option is specified, the user is prompted for confirmation
                 before each directory's contents are processed (as well as
                 before the attempt is made to remove the directory).  If the
                 user does not respond affirmatively, the file hierarchy
                 rooted in that directory is skipped.

     -r          Equivalent to -R.

     -v          Be verbose when deleting files, showing them as they are
                 removed.

     -W          Attempt to undelete the named files.  Currently, this option
                 can only be used to recover files covered by whiteouts.

이상입니다.