안녕하세요 가야태자 @talkit 입니다.
리눅스/Linux 편집기를 사용해보자 vi/vim 열고(Open) 닫기(Close) https://talkit.tistory.com/591
리눅스/Linux vi/vim NIX에서 가장 유명한 텍스트 편집기 - 글쓰기. One of the best text editor on NIX fields. - Writing https://talkit.tistory.com/699
리눅스/Linux cat 간단한 텍스트 파일 보기 Simple Text File Viewer https://talkit.tistory.com/675
리눅스/Linux 기본 명령어 - ls, 파일 목록 보기 dir(?) https://talkit.tistory.com/581
[리눅스/Linux] 파일 복사(Copy File) cp 명령어(Command) https://talkit.tistory.com/668
[리눅스/Linux] 파일 이동시키기(Move File)/이름 바꾸기(Change Name) mv 명령어(Command) https://talkit.tistory.com/667
리눅스에서 디렉토리를 만들어 보자. mkdir https://talkit.tistory.com/582
음 지금까지 리눅스 기본 관련글을 쓰면서 파일을 만들고,읽고, 목록확인하고, 이동 시키는 명령어는 열심히 알려 드렸습니다. 디렉토리 만들기도 했네요 ^^
위의 글들을 참고 하시면 되겠습니다. ^^
그런데 파일 삭제는 어떻게 할까요?
rm 이라는 명령어를 사용합니다.
RM(1) User Commands RM(1)
NAME
rm - remove files or directories
SYNOPSIS
rm [OPTION]... [FILE]...
DESCRIPTION
This manual page documents the GNU version of rm. rm removes each specified file. By default, it does not remove directories.
If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted.
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not affirmative, the file is skipped.
OPTIONS
Remove (unlink) the FILE(s).
-f, --force
ignore nonexistent files and arguments, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes
--interactive[=WHEN]
prompt according to WHEN: never, once (-I), or always (-i); without WHEN, prompt always
--one-file-system
when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument
--no-preserve-root
do not treat '/' specially
--preserve-root[=all]
do not remove '/' (default); with 'all', reject any command line argument on a separate device from its parent
-r, -R, --recursive
remove directories and their contents recursively
-d, --dir
remove empty directories
-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 might be possible to recover some of its contents, given sufficient expertise and/or time. For greater assurance that the contents are truly unrecoverable, consider using shred.
매뉴얼에서 확인해보면 저렇게 쓴다고 합니다.
저는 제 나름대로 또 설명하겠습니다.
rm [옵션들] 파일명|*|*패턴*
위와 같이 씁니다.
자 옵션들 중에서 -f -r -d -v 정도만 알면 되겠습니다.
-f 는 강제로 무조건이라는 뜻이고
-r 은 하위 디렉토리까지 포함 한다는 뜻이구요.
-d 는 빈 디렉토리만 이라는 뜻입니다.
-v 는 지워지는 파일을 보여줘라.
위와 같은 뜻이어서
같이 사용할 수 있습니다.
하나하나 한번 실습을 해보겠습니다.
cp ftpserver.txt ftpserver1.txt
cp ftpserver.txt ftpserver2.txt
cp ftpserver.txt ftpserver3.txt
cp ftpserver.txt ftpserver4.txt
cp ftpserver.txt ftpserver5.txt
일단 예전에 ftp 실습할때 만들어 둔 파일을 5개를 더 만들었습니다.
mkdir emptydir
mkdir notemptydir
cp ftp* notemptydir/
빈디렉토리와 안빈디렉토리를 만들고 안빈 디렉토리에 파일을 좀 복사해 두었습니다.
자 이제 rm 명령어를 실험해보겠습니다.
ls -al
rm ftpserver1.txt
ls -al
위 명령어들을 순서대로 쳐 보겠습니다. ^^
talkit@ubuntu:~$ ls -al
total 331068
drwxr-xr-x 17 talkit talkit 4096 Jan 3 03:28 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver1.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver2.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
talkit@ubuntu:~$ rm ftpserver1.txt
talkit@ubuntu:~$ ls -al
total 331064
drwxr-xr-x 17 talkit talkit 4096 Jan 3 03:31 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver2.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
위와 같이 나옵니다. 앞에 있었던 ftpserver1.txt 가 사라졌습니다.
이번에는 *를 이용해서 지워 보겠습니다. 그래서 조금 더 파일을 만들어 보겠습니다.
cp ftpserver.txt ftpserver11.txt
cp ftpserver.txt ftpserver12.txt
cp ftpserver.txt ftpserver13.txt
cp ftpserver.txt ftpserver14.txt
cp ftpserver.txt ftpserver15.txt
cp ftpserver.txt ftpserver21.txt
cp ftpserver.txt ftpserver22.txt
cp ftpserver.txt ftpserver23.txt
cp ftpserver.txt ftpserver24.txt
cp ftpserver.txt ftpserver25.txt
cp ftpserver.txt ftpserver31.txt
cp ftpserver.txt ftpserver32.txt
cp ftpserver.txt ftpserver33.txt
cp ftpserver.txt ftpserver34.txt
cp ftpserver.txt ftpserver35.txt
이정도 해보겠습니다. ^^
rm ftpserver2*.txt
위와 같이 명령어를 내려 보십시오.
ls -al
total 331124
drwxr-xr-x 17 talkit talkit 4096 Jan 3 03:33 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver11.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver12.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver13.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver14.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver15.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver21.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver22.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver23.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver24.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver25.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver2.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver31.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver32.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver33.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver34.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver35.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
talkit@ubuntu:~$ rm ftpserver2*.txt
talkit@ubuntu:~$ ls -al
total 331100
drwxr-xr-x 17 talkit talkit 4096 Jan 3 03:33 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver11.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver12.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver13.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver14.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver15.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver31.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver32.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver33.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver34.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver35.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
실행을 하면 위와 같이 2로 시작하는 아이들이 모두 사라졌습니다.
자 그러면, 디렉토리를 한번 지워 보겠습니다.
아무 옵션없이요 ^^
rm emptydir
저명령어를 내렸더니 아래와 같이 나옵니다.
rm emptydir
rm: cannot remove 'emptydir': Is a directory
디렉토리여서 못지원다. ^^
cp -r emptydir emmptydir1
cp -r emptydir emmptydir2
cp -r emptydir emmptydir3
cp -r emptydir emmptydir4
cp -r emptydir emmptydir5
빈디렉토리르 조금 늘렸습니다.
자 저 중에서 1번을 -d 옵션을 사용해서 지워 보겠습니다.
rm -d emptydir1
emptydir1이 없어진 모습은 아래 실행 결과에서 확인 할 수 있습니다.
ls -al
total 331120
drwxr-xr-x 22 talkit talkit 4096 Jan 3 03:38 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir1
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir2
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir3
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir4
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:38 emmptydir5
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver11.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver12.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver13.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver14.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver15.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver31.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver32.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver33.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver34.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver35.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
talkit@ubuntu:~$ rm -d emmptydir1
talkit@ubuntu:~$ ls -al
total 331116
drwxr-xr-x 21 talkit talkit 4096 Jan 3 03:38 .
drwxr-xr-x 3 root root 4096 Dec 25 00:12 ..
-rw------- 1 talkit talkit 4624 Jan 1 07:21 .bash_history
-rw-r--r-- 1 talkit talkit 220 Dec 25 00:12 .bash_logout
-rw-r--r-- 1 talkit talkit 3771 Dec 25 00:12 .bashrc
drwxrwxr-x 11 talkit talkit 4096 Dec 28 06:51 .cache
drwx------ 12 talkit talkit 4096 Dec 29 06:10 .config
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Desktop
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Documents
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Downloads
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir2
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir3
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:37 emmptydir4
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:38 emmptydir5
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 emptydir
-rw-r--r-- 1 talkit talkit 35 Dec 30 00:27 ftpclient.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver11.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver12.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver13.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver14.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver15.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver31.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver32.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver33.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver34.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:33 ftpserver35.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver3.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver4.txt
-rw-rw-r-- 1 talkit talkit 35 Jan 3 03:27 ftpserver5.txt
-rw-rw-r-- 1 talkit talkit 35 Dec 30 00:27 ftpserver.txt
drwx------ 3 talkit talkit 4096 Dec 25 00:21 .gnupg
-rw------- 1 talkit talkit 35 Dec 29 06:34 .lesshst
drwxr-xr-x 3 talkit talkit 4096 Dec 25 00:21 .local
-rw-rw-r-- 1 talkit talkit 338882654 Dec 21 05:26 mattermost-7.5.2-linux-amd64.tar.gz
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Music
drwxrwxr-x 2 talkit talkit 4096 Jan 3 03:28 notemptydir
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Pictures
-rw-r--r-- 1 talkit talkit 807 Dec 25 00:12 .profile
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Public
-rw-r--r-- 1 talkit talkit 0 Dec 28 06:43 .sudo_as_admin_successful
drwxrwxr-x 2 talkit talkit 4096 Dec 30 00:37 temp
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Templates
drwxr-xr-x 2 talkit talkit 4096 Dec 25 00:21 Videos
talkit@ubuntu:~$
잘 확인해보십시오.
그러면 notempdydir을 -d를 주고 지워 보겠습니다.
cp -r notemptydir notemptydir1
cp -r notemptydir notemptydir2
rm -d notemptydir1
rm: cannot remove 'notemptydir1': Directory not empty
일부러 디렉토리를 하나 더 만들고 지워 봤습니다.
그랬더니 이번에는 비워 있지 않은 디렉토리랍니다.
원래는 notemptydir1에 들어가서 모든 파일을 지원 다음에 한칸 위에가서 -d로 파일을 지워야 합니다.
한번 해보면 아래와 같습니다.
cd notemptydir1/
talkit@ubuntu:~/notemptydir1$ ls
ftpclient.txt ftpserver1.txt ftpserver2.txt ftpserver3.txt ftpserver4.txt ftpserver5.txt ftpserver.txt
talkit@ubuntu:~/notemptydir1$ rm *
talkit@ubuntu:~/notemptydir1$ cd ..
talkit@ubuntu:~$ rm -d notemptydir
rm: cannot remove 'notemptydir': Directory not empty
talkit@ubuntu:~$ rm -d notemptydir1
자 보이시나요 ^^
디렉토리 이동해서 지우고, 위로 이동해서 다시 디렉토리지우고 번거럽지요.
그걸 한번 해결 해주는 없션이 -r 입니다.
rm -r notemptydir2
1번은 제가 지워 버려서 ^^ 2번을 이제 한번 지워 보겠습니다.
rm -rv notemptydir2
removed 'notemptydir2/ftpserver5.txt'
removed 'notemptydir2/ftpclient.txt'
removed 'notemptydir2/ftpserver2.txt'
removed 'notemptydir2/ftpserver3.txt'
removed 'notemptydir2/ftpserver.txt'
removed 'notemptydir2/ftpserver4.txt'
removed 'notemptydir2/ftpserver1.txt'
removed directory 'notemptydir2'
일부러 v 옵션을 붙여서 해봤습니다. 그랬더니 지워지는 모습이 보이고 잘 지워집니다.
그러면 남은 옵션이 -f 입니다.
해보겠습니다.
-f는 보통 -i 옵션이 알리아스로 주어져 있을때 같이 사용합니다. 그런데 우분투는 -i 가 없어서 ^^
그래서 -f 옵션을 실습해 보겠습니다.
rm -rfv notemptydir
원래 지우려고 만든 디렉토리 들이라 ^^
rm -rfv notemptydir
removed 'notemptydir/ftpserver5.txt'
removed 'notemptydir/ftpclient.txt'
removed 'notemptydir/ftpserver2.txt'
removed 'notemptydir/ftpserver3.txt'
removed 'notemptydir/ftpserver.txt'
removed 'notemptydir/ftpserver4.txt'
removed 'notemptydir/ftpserver1.txt'
removed directory 'notemptydir'
위와 같이 잘 지워 집니다.
처음에는 제가 처음에 가르쳐 드린 방법으로 하시는게 좀 더 안전 합니다.
디렉토리 안의 파일 먼저 지우고
위로 이동해서 파일 지우는 방법이요
하지만, 서버 디렉토리가 또 있을수도 있으니 ^^
익숙해지시면 -rfv 옵션을 잘 사용하셔야 합니다.
정말 위험하니까요 ^^
리눅스는 휴지통이 있는 것도 아니어서 바로 지워진다고 생각하셔야 합니다. ^^
자나깨나 rm 조심입니다. ^^
감사합니다.
Mattermost에 빠져 있다가 다시 리눅스 글입니다. ^^