How to delete and remove files on Fedora Linux

last updated in Categories , ,

I am a new Fedora Linux user. How do I delete and remove a file on Fedora Linux based system?

You need to use the rm command. It tries to remove the files specified on the command line. Use the rm command to delete files and directories on Fedora Linux. This page shows how to delete and remove files on Fedora Linux.

Command to delete and remove files on Fedora Linux

The syntax is as follows for the rm and unlink command to remove files on Fedora Linux:

  1. Open the Fedora terminal application (bash shell)
  2. Type any one of the following command to delete a file named fedora.nixcraft.txt in the current directory
  3. rm fedora.nixcraft.txt
    OR
    unlink fedora.nixcraft.txt

Let use see all rm command options to delete and remove files on Fedora Linux.

Delete multiple files

Type the following command to delete the file named delta.txt, bar.doc, and dance.jpg located in the current directory:
[vivek@fedora ~]$ rm delta.txt bar.doc dance.jpg
You can specify path too. If a file named delta.txt located in /tmp/ directory, you can run:
[vivek@fedora ~]$ rm /tmp/delta.txt
[vivek@fedora ~]$ rm /tmp/delta.txt /home/vivek/dance.jpg /home/vivek/data/bar.doc

Fedora Linux delete a file and prompt before every removal

To get confirmation before attempting to remove each file pass the -i option to the rm command on Fedora Linux:
[vivek@fedora ~]$ rm -i filename
[vivek@fedora ~]$ rm -i delta.txt

Force rm command on Fedora Linux to explain what is being done with file

Pass the -v option as follows to get verbose output on Fedora Linux box:
[vivek@fedora ~]$ rm -v filename
[vivek@fedora ~]$ rm -v cake-day.jpg

Fedora Linux delete all files in folder or directory

You need to pass the following options:
[vivek@fedora ~]$ rm -rf dir1
[vivek@fedora ~]$ rm -rf /path/to/dir/
[vivek@fedora ~]$ rm -rf /home/vivek/oldschoolpics/

It will remove all files and subdirectories from a directory. So be careful. Always keep backups of all important data on Fedora Linux.
Delete and remove files on Fedora Linux

Fedora Linux delete file begins with a dash or hyphen

If the name of a file or directory or folder starts with a dash (- or hyphen --), use the following syntax:
[vivek@fedora ~]$ rm -- -filename
[vivek@fedora ~]$ rm -- --filename
[vivek@fedora ~]$ rm -rf --dirname
[vivek@fedora ~]$ rm ./-file
[vivek@fedora ~]$ rm -rf ./--dirname

Do not run ‘rm -rf /‘ command as an administrator/root or normal Fedora Linux user

rm -rf (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Fedora Linux disasters. The rm -rf / variant of the command, if run by an administrator, would cause the contents of every writable mounted filesystem on the computer to be deleted. Do not try these commands on Fedora Linux:
[vivek@fedora ~]$ rm -rf /
[vivek@fedora ~]$ rm -rf *

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.