main logo

How to Delete Files and Directories in CentOS?

How to Delete Files and Directories in CentOS?

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.

Total Time Needed: 30 Minutes

Required tools:

CentOS

Steps to delete files and directories in CentOS

Step 1 : To delete empty directories
Use the command rmdir. For example, to remove the Directory DIr2, type the command
rmdir Dir2

Step 2 : To delete a file
Use 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

Step 3 : To remove a Non-empty directory
Use 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.

Step 4 : To Remove files/directories without asking for confirmation
Use 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.

Step 5: To delete a file and see the summary
Use 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.

Step 6: To Delete a directory
Use 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.

Conclusion:
Hope you understand how to delete files and directories in CentOS. If you have any doubts please contact Medha Hosting. Our Linux experts will help you 24/7.
Read Here: How to View Files in CentOS?

Rakshitha
Rakshitha
Rakshitha is a cloud hosting expert who helps businesses get the most out of their cloud services. She has experience setting up and managing cloud environments to improve performance and scalability. With her cloud certification, Rakshithe provides clear advice on how to use cloud solutions effectively for better business results.
Share
Contents

Related Articles

medhacloud logo
USA:
Medha Cloud Solutions LLC
30 N Gould St Ste R, Sheridan, WY 82801,
Phone: +1 646 775 2855

India:
Medha Cloud Solutions Private Limited
#74, 7th Cross, Krishna Garden InCity Layout. Chikka Kammanahalli, Banneraghatta Road, Bangalore 560083
Phone:+91 93536 44646

E-Mail: support@medhahosting.com
©Medha Cloud 2024. All rights reserved.