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

Delete File

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

Delete multiple files

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

# rm –i test.txt

Delete file with prompt

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

# rm -rf <directoryname>

Recursively delete files

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

# rmdir <directory>

Remove a directory