How to delete files in Linux

In Linux, you can easily delete single files, groups of files, or entire folders. However, this works differently in Linux than in Windows. Keep reading to find out about different methods for removing files in Linux.

Free VPS Trial
30-day money-back guarantee

Try out your VPS for 30 days. If you're not satisfied, you get your money back.

Deleting files in Linux with a file manager

Depending on the distribution and desktop environment you’re using, you’ll have Nautilus, Dolphin or another Linux file manager on your computer. Using these standard file managers, you can remove Linux files in just a few simple steps.

  1. Navigate in the file manager to the files that you want to delete.
  2. Hold down the left mouse button and select the files that you want to delete.

3. Right-click on one of the files to open the context menu. Depending on the distribution you’re using, you’ll find a menu item such as “Move to Trash” or “Delete File”.

Tip

Instead of right-clicking, you can simply press [Del] to remove the selected files.

Deleting files in Linux with the terminal

Considering the large array of commands available in the terminal, it’s no surprise that you can use the command line to delete files in Linux. To do so, complete the following steps:

  1. Open the file manager and navigate to the files that you want to delete. Alternatively, you can use the command “cd/path/to/the/file” to go directly to the files in the terminal.
  2. Right-click on the window to open the context menu, and then click on “Open in Terminal”.

3. Use the command “rm” (short for “remove”) to delete a single file or multiple files.

A closer look at the “rm” command

Depending on whether you want to delete a single file, multiple files, or all of the files of a certain file type, the “rm” command will look slightly different.

Deleting a single file

You can quickly and easily delete a single file with the command “rm” followed by the file name.

rm DeleteMe.odt

Deleting multiple files

To delete multiple files at once, simply list all of the file names after the “rm” command. File names should be separated by a space.

rm DeleteMe.odt DeleteMe2.odt

Deleting files with a specific file name

You can also remove all Linux files with a certain file name in the terminal.

rm *Delete*

Deleting files of a certain file type

If you have a folder that contains different file types and want to delete all the files of a certain type - for example, .pdf or .odt - simply enter the command “rm” followed by an asterisk and the file type.

rm *.odt

In this case, you’ll delete all files with the ending .odt.

Deleting all the files in a folder

If you want to delete all of the files and subfolders of a certain folder, enter the following command into the terminal:

rm -r Files/*

In this case, all of the files in the folder “Files” will be deleted. The folder itself will remain. Of course it’s also possible to delete a Linux directory, including all the files it contains.

Tip

Your files are taking up too much space, but you still don’t want to delete them? It’s very easy to archive and compress files in Linux!

Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top