In Linux/Unix based system, file can be removed/deleted using command "rm" but it won't help if directories/folders and their contents need to be removed/deleted. In such cases option "-r or -R" need to be used with "rm" command to remove/delete directories/folders and their contents recursively.
Syntax:
rm -R <directory_name>
Option:
-r, -R :recursive- remove directories and their contents recursively
-f :force- ignore nonexistent files, never prompt
Usage:
rm -R <diectory_name>
rm -Rf <directory_name>
Example:
[root@Linux]# rm -r mydocs
rm: descend into directory `mydocs'? y
rm: remove regular empty file `mydocs/file2'? y
rm: remove regular empty file `mydocs/file3'? y
rm: remove regular empty file `mydocs/file1'? y
rm: remove directory `mydocs'? y
[root@Linux]#
rm: descend into directory `mydocs'? y
rm: remove regular empty file `mydocs/file2'? y
rm: remove regular empty file `mydocs/file3'? y
rm: remove regular empty file `mydocs/file1'? y
rm: remove directory `mydocs'? y
[root@Linux]#
!! Directory/folder and their contents deleted without prompting while using option "f" !!
[root@Linux]# rm -rf mydocs2
[root@Linux]#
[root@Linux]# rm -rf mydocs2
[root@Linux]#
Linux/Unix - Remove/Delete Directories/Folders And Their Contents Recursively
Reviewed by Admin
on
11:54:00
Rating: