리눅스 파일 삭제 - linugseu pail sagje

리눅스에서 파일 및 디렉터리를 삭제하는 명령어는 rm을 이용하면 된다. 리눅스에서는 파일을 한 번 삭제를 하면 윈도와는 달리 휴지통이라는 개념이 없어서 복구를 할 수 없으니 신중히 사용해야 합니다.

1. 단일 파일 지우기

단일 파일은 rm 명령어 뒤에 파일명을 같이 입력하면 됩니다.

bitnami@172-26-14-3# rm 파일명

2. 여러 개 파일 지우기

파일명을 띄어쓰기 구분자로 계속 나열해주면 여러개의 파일을 지울 수 있습니다.

bitnami@172-26-14-3# rm 파일명 파일명 파일명 파일명 ...

3. 확장자명으로 전부 지우기

리눅스에서 * 문자는 전체를 의미 합니다. 반대로 a.* 이렇게 명령어를 날리면 a. 으로 시작 되는 모든 파일을 지울 수 있습니다.

bitnami@172-26-14-3# rm *.txt

4. 하위 디렉토리까지 강제로 지우기

리눅스에서는 폴더 하위에 파일이 있거나 다른 폴더가 있다면 삭제를 진행할 수 없습니다. 강제 옵션을 이용하여 지워주면 한 번에 지울 수 있습니다.

bitnami@172-26-14-3# rm -rf 폴더명

rm

rm은 remove의 약어로서 파일이나 디렉토리를 삭제하는 명령어이다.

사용형식 : rm [옵션] 파일명

test 파일삭제

rm test

test 파일을 삭제할때 삭제확인과정을 거치치 않음

rm -f test

home 디렉토리를 삭제

rm -r home/

비어있지 않은 디렉토리는 -r 옵션 없이는 삭제할 수 없다.

rmdir 은 디렉토리를 삭제할때 사용하나 일반적으로 rm -r 을 이용한 삭제를 한다.

'리눅스 > Linux 일반' 카테고리의 다른 글

리눅스 cat, more, less, head, tail - 파일내용 확인  (2) 리눅스 mkdir - 새디렉토리 만들기  (2) 리눅스 cp - 복사  (0) 리눅스 ls - 파일리스팅  (0) 리눅스 SSH 보안 및 sudo 설정  (0)
2013.06.13
2013.06.13
2013.06.12
2013.06.12
2013.06.06

rm은 remove의 약자로, 파일 또는 디렉토리를 삭제하는 명령어입니다.

차례

  • 1 파일 삭제하기
  • 2 디렉토리 삭제하기

파일 삭제하기

  • abc.txt 파일을 삭제합니다. 삭제할 건지 다시 묻습니다. y 또는 yes를 입력하면 삭제합니다.
rm abc.txt

  • 확장자가 txt인 모든 파일을 삭제합니다. 각 파일에 대해서 삭제할 건지 묻습니다.
rm *.txt
  • 현재 디렉토리에 있는 모든 파일을 삭제합니다. 각 파일에 대해서 삭제할 건지 묻고, 디렉토리가 있다면 삭제할 수 없다는 메시지가 나옵니다.
rm *
  • -f 옵션을 붙이면 삭제할 건지 다시 묻지 않고 바로 삭제합니다.
rm -f abc.txt
  • 현재 디렉토리에 있는 모든 파일을 바로 삭제합니다. 디렉토리는 삭제하지 않습니다.
rm -f *

디렉토리 삭제하기

  • dir1 디렉토리를 삭제합니다. 디렉토리를 삭제할 때는 -r 옵션을 붙입니다.
rm -r dir1
  • f 옵션을 추가하면 삭제할 건지 묻지 않고 바로 삭제합니다.
rm -rf dir1
  • 현재 디렉토리에 속한 모든 파일과 디렉토리를 삭제합니다. -rf 옵션은 주의해서 사용해야 합니다.
rm -rf *

같은 카테고리의 다른 글

리눅스 / 명령어 / systemctl

서비스 관리 service_name은 서비스 이름으로 바꾸어 사용합니다. 예를 들어 Apache라면 httpd, MariaDB라면 matiadb. 서비스 상태 확인 systemctl status service_name.service 서비스 시작 systemctl start service_name.service 서비스 재시작 systemctl restart service_name.service 서비스 중지 systemctl stop service_name.service 부팅 시 서비스 자동 시작 systemctl enable service_name.service 부팅 시 서비스 자동 시작 해제 systemctl disable service_name.service 서비스 목록 보기 systemctl list-units --type=service

리눅스 / LVM / 만드는 방법, 수정하는 방법, 삭제하는 방법

1TB 디스크와 2TB 디스크를 추가했다고 하자. 디스크 크기에 맞게 그대로 사용할 수도 있지만, 3TB 하나인 것처럼 사용하거나 1.5TB 두 개인 것처럼 사용하고 싶을 수도 있다. 즉, 물리적인 디스크 크기와 무관하게 자유롭게 볼륨을 만들고 싶은 것이다. 이럴 때 사용하는 것이 LVM(Logical Volume Manager)이다. 여러 개의 볼륨을 하나로 묶은 후 다시 배분하여 사용한다.(이렇게 ...

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

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있습니다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용합니다. 각 명령어로 find 명령어를 찾아보겠습니다. # which find /usr/bin/find # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz # 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 옵션으로 출력 개수를 정할 수 있습니다. # locate ...

리눅스 / 명령어 / ls / 디렉토리와 파일 목록 출력하는 명령어

ls는 list의 약어로, 디렉토리와 파일 목록을 출력하는 명령어이다. ls 디렉토리명 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. 숨김 파일은 나오지 않는다. 디렉토리명을 생략하면 현재 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. 예를 들어 다음과 같이 명령하면 /var 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. ls /var ls -a, ls -l -a 옵션을 붙이면 숨김 파일도 출력한다. -l 옵션을 붙이면 소유자, 파일 크기 ...

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

리눅스에서 네트워크 정보는 주로 ifconfig, ip addr 명령어로 확인합니다. 그런데, gateway 정보는 나오지 않습니다. 만약 gateway 정보가 필요하다면 route 명령어를 사용합니다.

리눅스 / 명령어 / cat / 파일 내용 출력하는 명령어

다음과 같은 두 개의 파일이 있다고 할 때 file1 1-1 1-2 1-3 file2 2-1 2-2 2-3 cat filename cat 뒤에 파일 이름을 넣으면 파일 안의 내용을 보여줍니다. # cat file1 1-1 1-2 1-3 파일 이름을 연달아 넣으면 연속하여 파일의 내용을 보여줍니다. # cat file1 file2 1-1 1-2 1-3 2-1 2-2 2-3 cat filename -n -n 옵션을 붙이면 줄번호를 보여줍니다. # cat -n file1 1 1-1 2 1-2 3 1-3 # cat -n file1 file2 1 1-1 2 1-2 3 1-3 4 2-1 5 2-2 6 ...

리눅스 / 그룹 / 그룹 조회, 그룹 추가, 그룹 삭제, 그룹 수정

그룹 조회 그룹 목록은 /et/group 파일에 있습니다. cat 명령어로 전체를 조회하거나... cat /etc/group tail 명령어로 마지막 부분을 조회할 수 있습니다. # tail -n 5 /etc/group avahi:x:70: slocate:x:21: rngd:x:974: tcpdump:x:72: vboxsf:x:973: X:Y:Z 형식으로 나오는데, X는 그룹 이름, Y는 그룹 비밀번호, Z는 그룹 ID입니다. 그룹 추가 groupadd 명령으로 그룹을 추가합니다. # groupadd group-1 # tail -n 5 /etc/group slocate:x:21: rngd:x:974: tcpdump:x:72: vboxsf:x:973: group-1:x:1000: 그룹 삭제 groupdel 명령으로 그룹을 삭제합니다. # ...

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

로그아웃 명령어 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분 후에 종료 shutdown -P 10 13시에 종료 shutdown -P 13:00 취소 shutdown -c 기타 10분 후에 종료할 거라는 메시지를 사용자에게 보내지만, 종료하지는 ...

리눅스 / RAID / Linear RAID, RAID0, RAID1, RAID5, RAID6

RAID 뜻과 종류 RAID Redundant Array of Inexpensive Disk or Redundant Array of Independent Disk 여러 개의 하드디스크를 하나처럼 사용하게 하는 기술. 예를 들어 1TB 하드디스크 두 개를 묶어서 2TB 하드디스크처럼 사용할 수 있다. 크게 하드웨어 RAID와 소프트웨어 RAID로 구분할 수 있다. 하드웨어 RAID는 성능이 좋으나 비싸다. 소프트웨어 RAID는 운영체제에서 지원하는 것으로 OS RAID라고도 한다. Linear RAID 두 ...

Toplist

최신 우편물

태그