In this post, we will see how to Delete Files and directories using terminal commands in CentOS. CentOS is a Community Enterprise operating system which mainly focuses on the server. It is a part of Linux Operating System Distribution, and it is free to use. First, open the terminal.

Steps To Delete Files And Directories In CentOS

Step 1 : To Delete Empty DirectoriesUse the command rmdir. For example, to remove the Directory DIr2, type the command rmdir Dir2

sfbnfykihl

Step 2 : To Delete a FileUse the command rm to delete files. For example, to delete file3. Type the command rm file3 and press enter. It will ask for a confirmation type y and press enter for yes

ZDBfgmm

Step 3 : To Remove a Non-empty DirectoryUse the command rm –r . For example, To delete a directory dir1, which is non-empty. Type the command rm –r dir1 , it will ask a confirmation to descend to all the available objects in dir1 and to remove them type y for YES and press enter.

ZVf fd sfvfs

Step 4 : To Remove files/directories Without Asking for ConfirmationUse the command rm –f to delete without terminal asking for a confirmation. For example, to delete file2 type rm –f file2 and press enter. You will see that file2 is deleted without asking you for a confirmation.

ZDVfsnfdn

Step 5: To Delete a File and See the SummaryUse the command rm –v to delete the file and see the summary. for example, to delete file4 without asking for confirmation and see the summary type rm –vf file4 and press enter. You will see that file4 is deleted and check the summary.

ZDBdgmg

Step 6: To Delete a DirectoryUse the command rm- rvf . For example, to remove directory dir3 , check the summary and delete it without the terminal asking for confirmation. Combine the commands r,v,f with rm. Type rm –rvf dir3 and press enter. You can see the summary that the directory is deleted.

zDBfdnfhm

Conclusion:Hope you understand how to delete files and directories in CentOS. If you have any doubts please contact Hostina. Our Linux experts will help you 24/7.