리눅스 / 명령어 / 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'
같은 카테고리의 다른 글

리눅스 / 명령어 / 연산자 - ;, &&, ||

리눅스 셸에서 ;, &&, || 는 명령어 실행 방식을 제어하는 연산자입니다. 각 기호의 의미와 사용법은 다음과 같습니다.

Ubuntu 18.04 Server / 시간대(time zone) 설정하는 방법

Ubuntu 18.04 Server / 시간대(time zone) 설정하는 방법

현재 서버의 시간대 확인 현재 서버에 설정된 시간대는 date 명령어로 확인할 수 있다. # date 시간대 설정 방법 1 - dpkg-reconfigure tzdata 시간대를 설정하고 싶다면 다음과 같이 명령한다. # dpkg-reconfigure tzdata 한국이라면 Asia를 선택하고 Seoul을 선택합니다. 시간대 설정 방법 2 - tzselect tzselect 명령으로 설정할 수 있다. 번호를 입력하여 시간대를 정한다. # tzselect Please identify a location so that time ...

리눅스 / 게이트웨이(gateway) 확인하는 방법

리눅스에서 네트워크 정보는 주로 ifconfig, ip addr 명령어로 확인한다. 그런데, gateway 정보는 나오지 않는다. 만약 gateway 정보가 필요하다면 route 명령어를 사용한다. Ubuntu애서 명령어가 없다고 나오면 net-tools를 설치한다. apt install net-tools

Ubuntu 22.04 Server / 백신 프로그램 ClamAV 설치 및 사용법

ClamAV ClamAV는 리눅스에서 사용할 수 있는 백신 프로그램이다. 우분투 패키지에 포함되어 있으므로 apt 명령으로 쉽게 설치하고 사용할 수 있다. 설치 # apt install clamav 사용법 데이터베이스 업데이트 clamav-freshclam 서비스를 중지한다. # systemctl stop clamav-freshclam freshclam 명령으로 업데이트한다. # freshclam clamav-freshclam 서비스를 시작한다. # systemctl start clamav-freshclam 검사 home 디렉토리와 그 하위 디렉토리를 검사한다. # clamscan -r /home 검사 결과는 다음처럼 나온다. ----------- SCAN SUMMARY ----------- Known viruses: ...

Ubuntu 18.04 Server / PHP 최신 버전으로 업그레이드하는 방법

Ubuntu 패키지로 설치한 PHP 버전보다 PHP 최신 버전이 더 높을 수 있습니다. 예를 들어 패키지로 설치한 PHP의 버전은 7.0, 최신 버전은 7.2일 수 있다는 것이죠. 만약 최신 버전의 PHP를 사용해야 한다면 다음의 방법으로 설치할 수 있습니다. PHP를 처음 설치하는 경우 저장소를 추가합니다. # add-apt-repository ppa:ondrej/php 패키지 정보를 업데이트합니다. # apt-get update PHP를 설치합니다. # apt-get install php PHP가 ...

Ubuntu 24.04 Server / 고정 IP 설정하는 방법

네트워크 설정 파일은 /etc/netplan 디렉토리 안에 있는 yaml 파일입니다. 파일 이름은 시스템마다 다를 수 있습니다. # ll /etc/netplan total 12 drwxr-xr-x 2 root root 4096 Apr 27 23:00 ./ drwxr-xr-x 108 root root 4096 Apr 27 23:06 ../ -rw------- 1 root root 389 Apr 27 23:00 50-cloud-init.yaml DHCP라면 설정 파일이 다음과 ...

리눅스 / 사용자 / 사용자 조회, 사용자 추가, 사용자 삭제, 사용자 수정

사용자 조회 모든 사용자를 출력합니다. # cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin ... root과 useradd 또는 adduser를 통해 생성한 사용자 계정을 출력합니다. # grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash jb:x:1000:1000:JB:/home/jb:/bin/bash 사용자 추가 useradd jb 사용자를 만듭니다. useradd jb 사용자 홈 디렉토리도 같이 만들고 싶다면 -d 옵션을 사용합니다. useradd jb -d /home/jbdir jb 사용자의 비밀번호를 만듭니다. passwd jb adduser adduser 명령어로 사용자를 추가할 수 있습니다. useradd와는 달리 사용자 홈 디렉토리를 자동으로 만들고, 비밀번호 ...

리눅스 / 버전 확인하는 방법

리눅스에서 현재 사용 중인 배포판의 버전을 확인하는 방법은 여러 가지가 있습니다. 그 중 두 가지를 소개합니다. hostnamectl 명령어로 확인 hostnamectl 명령어로 리눅스 버전을 확인할 수 있습니다. 아래는 Rocky Linux에서 실행한 결과입니다. # hostnamectl Static hostname: rocky-9-01 Icon name: computer-vm Chassis: ...

Ubuntu 16.04 / phpMyAdmin / 특정 IP에서만 접속 가능하게 만드는 방법

우분투 16.04에서 phpMyAdmin을 패키지로 설치했을 때, 기본 설정은 모든 IP에서 접속 가능입니다. 만약 특정 IP에서만 접속 가능하게 하려면 /etc/apache2/conf-available/phpmyadmin.conf에 다음 코드를 추가합니다. <Directory /usr/share/phpmyadmin> Order deny,allow Deny from all Allow from xxx.xxx.xxx.xxx </Directory> xxx.xxx.xxx.xxx는 접속하려는 IP로 바꿉니다. 여러 IP를 설정하고 싶을 때는 띄어쓰기로 구분합니다. <Directory /usr/share/phpmyadmin> Order deny,allow Deny from all ...

CentOS 7 / ntp로 시간 동기화 하는 방법

CentOS 7 / ntp로 시간 동기화 하는 방법

리눅스가 OS인 서버의 시간과 실제 시간을 동기화하는 방법 중의 하나는 ntp를 이용하는 것입니다. CentOS 7에 ntp를 설치하고 설정하는 방법을 요약합니다. ntp 설치 yum install ntp 동기화할 서버 주소 가까운 곳에 있는 시간 서버를 사용하는 게 좋습니다. (하지만, 설정을 변경하지 않아도 큰 문제는 없습니다.) 서버 주소는 http://www.pool.ntp.org/에서 구할 수 있습니다. 지역을 아시아로 했을 때의 서버 주소는 다음과 같습니다. server 0.asia.pool.ntp.org server ...