Linux Tutorial 06


rm – Remove Files And Directories


Delete zikzak_file_01 silently

$ ls -l
total 12
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:10 archive
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:11 archive02
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:12 archive03
-rw-r----- 1 zikzak u41687    0 Aug  2 17:05 zikzak_file_01
-rw-r----- 1 zikzak u41687    7 Aug  2 17:09 zikzak_file_02
-rw-r----- 1 zikzak u41687    7 Aug  2 17:09 zikzak_file_03

$ rm zikzak_file_01

$ ls -l
total 12
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:10 archive
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:11 archive02
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:12 archive03
-rw-r----- 1 zikzak u41687    7 Aug  2 17:09 zikzak_file_02
-rw-r----- 1 zikzak u41687    7 Aug  2 17:09 zikzak_file_03

Delete zikzak_file_01 after confirmation

$ rm -i zikzak_file_02
rm: remove regular file `zikzak_file_02'? y

$ ls -l
total 12
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:10 archive
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:11 archive02
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:12 archive03
-rw-r----- 1 zikzak u41687    7 Aug  2 17:09 zikzak_file_03

Delete the file  zikzak_file_03 and the directory archive03

$ rm -r zikzak_file_03 archive03

$ ls -l
total 8
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:10 archive
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:11 archive02

Same as above, except that if either file or directory do not exist, rm will continue silently.

$ rm -rf zikzak_file_01 archive02

$ ls -l
total 4
drwxr-x--- 2 zikzak u41687 4096 Aug  2 17:10 archive