리눅스 / 명령어 / rmdir / 빈 디렉토리 삭제하는 명령어

rmdir

rmdir은 빈 디렉토리를 삭제하는 명령어이다.

Remove the DIRECTORY(ies), if they are empty.

사용법

rmdir directory

  • a 디렉토리를 삭제한다.
# rmdir a
  •  비어있다면 삭제를 하고, 그렇지 않다면 다음을 출력한다.
rmdir: failed to remove ‘a’: Directory not empty

rmdir --ignore-fail-on-non-empty directory

  • 디렉토리가 비어있지 않아도 메시지를 출력하지 않는다.

rmdir -v directory

  • 현재 디렉토리 안에 있는 모든 비어있는 디렉토리를 삭제한다. v 옵션을 넣으면 작업 결과를 출력한다.
# rmdir -v *
  • 예를 들어 헌재 디렉토리에 a, b, c 디렉토리가 있고, a와 c는 빈 디렉토리, b는 비어있지 않은 디렉토리라면, 다음을 출력한다.
rmdir: removing directory, ‘a’
rmdir: removing directory, ‘b’
rmdir: failed to remove ‘b’: Directory not empty
rmdir: removing directory, ‘c’

rmdir -p directory

  • a/b/c를 삭제하고, a/b를 삭제하고, a를 삭제한다.
# rmdir -p a/b/c
  • 아래와 같다.
# rmdir a/b/c a/b a

rmdir --help

  • 도움말을 출력한다.
# rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.

      --ignore-fail-on-non-empty
                  ignore each failure that is solely because a directory
                    is non-empty
  -p, --parents   remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
                    similar to 'rmdir a/b/c a/b a'
  -v, --verbose   output a diagnostic for every directory processed
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/rmdir>
or available locally via: info '(coreutils) rmdir invocation'
같은 카테고리의 다른 글

리눅스 / 명령어 / alias / 명령어 별칭 만들기

긴 명령어 또는 복잡한 명령어를 자주 사용한다면 alias를 사용하자. 시간을 많이 절약할 수 있다. alias 목록 보기 alias를 실행하면 현재 등록된 alias를 출력한다. alias 예를 들어 ll을 실행한다는 것은 ls -alF를 실행하는 것과 같다. alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias ls='ls --color=auto' alias 만들기 alias는 다음과 같이 만든다. abc를 실행하는 ...

리눅스 / 배포판 / 우분투(Ubuntu) - 역사, 특징, 장점

우분투의 역사 우분투(Ubuntu)는 2004년 10월 20일에 첫 번째 버전이 출시된 이후로 리눅스 배포판 중에서 가장 인기 있는 배포판 중 하나로 자리매김했습니다. 우분투는 데비안(Debian) 리눅스를 기반으로 하며, 캐노니컬(Canonical Ltd.)의 설립자인 마크 셔틀워스(Mark Shuttleworth)가 주도하여 시작되었습니다. 셔틀워스는 우분투를 통해 누구나 쉽게 접근할 수 있는 무료 운영체제를 제공하고자 했습니다. 데비안 기반 우분투는 데비안의 강력한 패키지 관리 ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

리눅스 / 명령어 / scp

scp는 ssh 프로토콜을 이용하여 파일을 송수신하는 명령어이다. local → remote remote → local remote → remote 모두 가능하다. local → remote 파일 복사 # scp a.txt root@192.168.3.211:/temp/a.txt root@192.168.3.211's password: 명령어를 실행한 디렉토리에 있는 a.txt 파일을 192.168.3.211 컴퓨터에 root 계정으로 연결하여 복사한다. 원격 컴퓨터에 /temp 디렉토리가 없으면 복사되지 않는다. 원격 컴퓨터에 /temp 디렉토리가 있으면 a.txt로 복사된다. a.txt 파일이 이미 있다면 덮어쓴다. root 계정의 ...

리눅스 / 캐시 메모리 삭제하는 방법

free 명령어로 메모리 사용 현황을 볼 수 있다. 아래의 경우 free에 여유가 있는데, 만약 buff/cache 사용량이 많아 free에 공간이 없다면 시스템이 느려진다. 그런 경우 메모리 캐시를 삭제하여 속도를 향상 시킬 수 있다. # free total ...

리눅스 / 명령어 / rdate / 타임서버의 시간과 동기화해주는 명령어

rdate는 서버의 시간과 타임서버의 시간을 동기화해주는 명령어이다. rdate는 설치되어있지 않는 경우가 많으므로, 필요하다면 설치를 해야 한다. CentOS라면 # yum install rdate Ubuntu라면 # apt install rdate 와 같이 명령하여 설치할 수 있습니다. 타임서버의 시간을 확인할 때는 -p 옵션을 사용합니다. 현재 서버의 시간을 변경하지 않는다. # rdate -p time.bora.net 현재 서버의 시간을 타임서버의 시간으로 맞출 때에는 -s 옵션을 ...

리눅스 / 커널

리눅스 커널은 리눅스 운영체제의 핵심 구성 요소로, 시스템 하드웨어와 소프트웨어 간의 중재자 역할을 합니다. 커널은 시스템 자원을 관리하고, 프로세스 간의 통신을 지원하며, 기본적인 보안과 안정성을 제공합니다. 리눅스 커널은 자유 소프트웨어 및 오픈 소스 소프트웨어 개발 및 배포 모델에 따라 개발됩니다. 리눅스 커널의 주요 기능 프로세스 관리 프로세스 생성 및 종료 : 커널은 새로운 ...

리눅스 / crontab 사용법

cron & crontab cron은 특정 시간에 특정 작업을 수행하게 하는 시스템 대몬이다. 백업, 캐시 메모리 비우기 등 주기적으로 어떤 작업을 해야할 때 유용하다. crontab은 시간과 작업을 적은 텍스트 파일이다. 사용자별로 파일이 존재한다. cron은 모든 사용자의 crontab 파일을 찾아서, 적혀진 일정대로 작업을 수행한다. 작업 목록 보기 예약 작업 목록을 보고 싶다면 다음과 같이 명령한다. 사용자의 crontab ...

리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

ls -l ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다. 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다. 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 3개의 문자열은 소유자(그룹) 이외의 권한을 나타냅니다. 처음 나오는 jb는 소유자, 그 다음 ...

리눅스 / 로그아웃 명령어, 재부팅 명령어, 종료 명령어

로그아웃 명령어 # logout # exit 재부팅 명령어 즉시 재부팅 # reboot # shutdown -r now # init 6 일정 시간 또는 일정 시간 후 재부팅 10분 후 재부팅 # shutdown -r 10 12시에 재부팅 # shutdown -r 12:00 취소 # shutdown -c 종료 명령어 즉시 종료 # poweroff # shutdown -h now # shutdown -P now # halt -p # init 0 일정 시간 또는 일정 시간 후에 종료 10분 후에 종료 # ...