rm
: 삭제remove files or directories
-r
, -R
: remove directories and their contents recursivelyhyojin@computer:~$ ls -l
total 24
drwxr-xr-x 2 hyojin hyojin 4096 Aug 11 14:47 cleanUp
drwxr-xr-x 2 hyojin hyojin 4096 Sep 5 17:43 rmDir
drwxr-xr-x 3 hyojin hyojin 4096 Aug 30 14:52 test
drwxr-xr-x 3 hyojin hyojin 4096 Aug 9 17:36 test-py-project
drwxr-xr-x 4 hyojin hyojin 4096 Sep 5 16:29 test2
-rw-r--r-- 1 hyojin hyojin 1523 Aug 11 15:07 vim_shortcut_summary.txt
hyojin@computer:~$ ls -l rmDir
total 0
-rw-r--r-- 1 hyojin hyojin 0 Sep 5 17:43 rmtext.txt
hyojin@computer:~$ rm rmDir
rm: cannot remove 'rmDir': Is a directory
hyojin@computer:~$ rm -r rmDir
hyojin@computer:~$ ls -l
total 20
drwxr-xr-x 2 hyojin hyojin 4096 Aug 11 14:47 cleanUp
drwxr-xr-x 3 hyojin hyojin 4096 Aug 30 14:52 test
drwxr-xr-x 3 hyojin hyojin 4096 Aug 9 17:36 test-py-project
drwxr-xr-x 4 hyojin hyojin 4096 Sep 5 16:29 test2
-rw-r--r-- 1 hyojin hyojin 1523 Aug 11 15:07 vim_shortcut_summary.txt
-i
: prompt before every removal
-ri
./test3:
test3-1 test3.txt
./test3/test3-1:
test3-1.txt
-------------------------------------------------------------
hyojin@computer:~/test$ rm -ri test3
rm: descend into directory 'test3'? y
rm: descend into directory 'test3/test3-1'? y
rm: remove regular empty file 'test3/test3-1/test3-1.txt'? y
rm: remove directory 'test3/test3-1'? y
rm: remove regular empty file 'test3/test3.txt'? y
rm: remove directory 'test3'? y
-I
: prompt once before removing more than three files, or when removing recursively
-rI
./test3:
test3-1 test3.txt
./test3/test3-1:
test3-1.txt
-------------------------------------------------------------
hyojin@computer:~/test$ rm -rI test3
rm: remove 1 argument recursively? y
-d
: remove empty directories
hyojin@computer:~$ ls -l
total 24
drwxr-xr-x 2 hyojin hyojin 4096 Aug 11 14:47 cleanUp
drwxr-xr-x 2 hyojin hyojin 4096 Sep 5 17:03 emptyDir
drwxr-xr-x 3 hyojin hyojin 4096 Aug 30 14:52 test
hyojin@computer:~$ ls -l emptyDir
total 0
hyojin@computer:~$ rm emptyDir/
rm: cannot remove 'emptyDir/': Is a directory
hyojin@computer:~$ rm -d emptyDir/
hyojin@computer:~$ ls -l
total 20
drwxr-xr-x 2 hyojin hyojin 4096 Aug 11 14:47 cleanUp
drwxr-xr-x 3 hyojin hyojin 4096 Aug 30 14:52 test
mv
: 파일 이동 또는 파일명 변경move/rename files
mv <source> <destination>
╭─ ~/test/moveTest
╰─ ls -l
total 4
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 10:57 file1.txt
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 10:57 file2.txt
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 10:58 mvDir
╭─ ~/test/moveTest
╰─ mv file1.txt mvDir
╭─ ~/test/moveTest
╰─ ls -l
total 4
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 10:57 file2.txt
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 10:58 mvDir
╭─ ~/test/moveTest
╰─ ls -l mvDir
total 0
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 10:57 file1.txt
폴더/파일을 이동하려는 목적지 디렉토리가 존재하지 않으면 이름이 변경된다.
╭─ ~/test/mvDir
╰─ ls -l
total 4
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 11:10 fromDir
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:10 textfile1.txt
╭─ ~/test/mvDir
╰─ mv fromDir toDir
╭─ ~/test/mvDir
╰─ ls -l
total 4
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:10 textfile1.txt
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 11:10 toDir
cp
: 복사copy files and directories
mv <source> <destination>
-r
: copy directories recursively
╭─ ~/test/cpDir
╰─ ls -l
total 4
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 11:26 cpFromDir
╭─ ~/test/cpDir
╰─ ls -l cpFromDir
total 0
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:25 file1.txt
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:26 file2.txt
╭─ ~/test/cpDir
╰─ cp cpFromDir cpToDir
cp: -r not specified; omitting directory 'cpFromDir'
╭─ ~/test/cpDir
╰─ cp -r cpFromDir cpToDir
╭─ ~/test/cpDir
╰─ ls -l
total 8
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 11:26 cpFromDir
drwxr-xr-x 2 hyojin hyojin 4096 Sep 8 11:26 cpToDir
╭─ ~/test/cpDir
╰─ ls -l cpFromDir
total 0
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:25 file1.txt
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:26 file2.txt
╭─ ~/test/cpDir
╰─ ls -l cpToDir
total 0
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:26 file1.txt
-rw-r--r-- 1 hyojin hyojin 0 Sep 8 11:26 file2.txt