Categories: CentOSLinuxShell

How to delete files on Rocky Linux using the command line

The rm command is used to delete files in Linux. The rm command removes the specified files as it doesn't remove the directory. Be careful, as rm command is not asking for confirmation for the deletion of the file. If the file is gone, we can't recover the file. This tutorial will show us how to delete files in Rocky Linux safely.

The general syntax for deleting files is given below:

# rm <filename>

Use the following command to delete a file forcefully

# rm -f <filename>

The -f command option tells the rm command to remove the file forcefully.

If you want to delete the file, run the command rm test.txt. It will delete the file without prompting the configuration. If you wish to prompt for confirmation before deletion, use the -I flag. With the -f flag, delete the file without prompting the confirmation.

If you want to file, navigate to the terminal, and type the following command.

# rm test.txt

To delete the files at once, you can also do this with the help of the rm command.

# rm test.txt test2.txt test3.txt

If you want prompting before deletion, use the following command.

# rm –i test.txt

To remove all files & subdirectories from a directory, use the below-given command.

# rm -rf <directoryname>

To remove an empty directory, use rmdir instead of the rm command.

# rmdir <directory>

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago