How To Delete a File in Ubuntu

Removing a file in Ubuntu can be difficult; learn the easiest Ubuntu delete file processes in this article.

Removing a file in a Linux system is a fundamental task that users frequently carry out. Deleting these files creates extra spaces in your system that users can use to install new packages or save new files. If you're an Ubuntu user who doesn't understand how to delete a file or multiple files in Ubuntu, you're in luck. We'll explain how to delete files in Ubuntu using the command line or the GUI (Graphical User Interface). It's crucial to note that you need some permissions to delete a file in the Ubuntu Linux system; let's take a look.

Part 1. How To Delete a File in Ubuntu Using Graphical User Interface (GUI)

To delete a file using the GUI, you need to have writeable permissions on the file. Additionally, you have to be logged in as a root user on the Ubuntu system before you can delete a file through this process. The GUI option is best for you if you want to see the files before you delete them. This is because the GUI allows you to select and delete files in just a few clicks. Below are the simple steps to delete a file in Ubuntu through GUI.

Step 1: Open your file manager and navigate to the file's location before you delete it.

launch the file manager in ubuntu

Step 2: You can select multiple files to delete. Hold the Shift key as you choose the files, then delete them. This method allows you to select files next to each other. Alternatively, you can hold the Ctrl key as you choose the files, then press the 'Delete' button.

select files to delete in ubuntu

Step 3: Once deleted, files are not gone from the machine. Rather, they're moved to the Trash folder to be recovered.

move files to trash

Step 4: Locate the Trash folder and choose Empty Trash at the top of the menu.

empty trash of files

This action would automatically empty all the files stored in the Ubuntu Trash folder, ensuring that the files are gone permanently.

Part 2. How To Delete a File in Ubuntu Using Terminal

Another remove file Ubuntu method you can use is through the Terminal. There are two effective commands that you can use to delete a file in Ubuntu: the unlink and rm commands. The rm command is quite popular and removes multiple files from a folder or directory. On the other hand, the unlink command works to remove a single file at a time.

Remove a File in Ubuntu Using the rm Command

The rm command is effective for deleting directories and files in Ubuntu. It is a powerful command and should only be used cautiously, as files deleted through this method can be difficult to recover. You can use the following options alongside the rm command.

  • '-f'-This option deletes all read-only files from your system without requesting confirmation.
  • '-i'-This option prompts users for confirmation before removing or deleting a file.
  • '-v'-This option ensures the system displays the file names on the terminal screen while it is being deleted from the system.
  • '-I'-This option also shows the user prompt whenever you're trying to delete more than three files simultaneously. It's best used when you're deleting files recursively.
  • '-r' or '-R'-This option deletes the current directory alongside all files and subdirectories.
  • '-q'-This option suppresses every warning that might pop up. However, you'll still find the error messages displayed on the screen.

Using the rm command, you can either delete single or multiple files in the Ubuntu system. To delete a file in the Ubuntu system using the rm command. Below is the syntax to get it done:

$ rm path/to/file.txt

An example is if we want to remove a text file from the downloads folder. To do this, follow the steps below.

Step 1: First, open the Terminal and then run the rm command below

$ rm /jome/sam-pc/Downloads/demo.txt

rm command to delete file in ubuntu

Step 2: The prompt will ask you to confirm your actions to delete a write-protected file from Ubuntu, enter 'y', and then press the 'Enter' key. If the file isn't protected, the file will be deleted from your system without displaying a confirmation prompt.

Step 3: If you want to delete a single file with the command rm, run the below command.

rm DeleteMe.odt

deletea file in ubuntu with rm

Step 4: If you want to delete multiple files simultaneously, list the file names right after the rm command. You need to separate file names by space.

rm DeleteMe.odt DeleteMe2.odt

delete multiple files with rm command

Step 5: If you also want to remove all files with a specific file name, then you should run the command below.

rm *Delete*

delete files with a specific name

Step 6: If you have a folder containing various file types and want to delete all the files with this file type, enter the rm command closely followed by an asterisk and the file type. An example is:

rm *.odt

delete a file type in ubuntu

This would automatically delete all files that end with .odt.

Step 7: Delete all the files and subfolders in a specific folder. Enter the command below to complete the process.

rm -r files/*

delete files in a folder with rm command

In this case, it will delete all the files in the folder 'files.' The folder itself will remain, but it will be empty.

Remove Files in Ubuntu Using the unlink Command

Another Ubuntu delete file method you can use when deleting files through the Terminal is the unlink command. It allows you to delete a specified file from the system. How does it do this? The unlink command eliminates a file's symbolic link, ensuring the filename is no longer associated with any data.

To delete or remove a file using the unlink command, type the unlink command followed by the name of the file you would like to delete. The syntax of the unlink command is stated below:

unlink filename

delete file using the unlink command

Although the unlink command is similar to rm, you should note some crucial differences. The unlink command doesn't support any option apart from the -help (shows the help page) and -version (shows the version number) options. Due to this, you can't control how the unlink command behaves during the deletion process.

Additionally, the unlink command doesn't support multiple file names; you can only delete one file at a time.

Part 3. What To Do if You Accidentally Delete a File in Ubuntu?

If you mistakenly delete a file in Ubuntu, you can recover the file with Linux data recovery software like Wondershare Recoverit. Wondershare Recoverit is selected as the Leader in Data Recovery by G2 users because it is easy to navigate and assists users with hundreds of data loss scenarios. Some of the top features offered by Wondershare Recoverit include:

  • It works with all mainstream Linux distributions like Linux Mint, Ubuntu, Manjaro, Debian, etc.
  • It helps recover data from 500+ loss scenarios like disk formatting, power outage, lost partition, virus attack, and more.
  • Its simple interface allows you to recover data from Linux hard drives with just a few clicks.
Free Download

For Windows Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

Below is a clear video tutorial on recovering deleted files from Ubuntu using Recoverit Linux Recovery.

Free Download

For Windows Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

Alternatively, you can follow the steps outlined below to recover deleted files in Ubuntu.

Step 1: Launch the program after the installation and navigate to NAS and Linux Linux Recovery.

choose linux recovery

Step 2: Now, provide the required information to connect the data recovery tool to your Linux device. Once you provide the information, press 'Connect' to proceed.

create a remote connection

Step 3: Once the remote connection is established, Recoverit will begin an automatic scan to look for the deleted files in your Ubuntu system. You can filter the results by date created or modified, file types, and more. You can also stop the scan midway if you find the desired file.

scan for deleted files in ubuntu

Step 4: Once the scan is complete, you can preview the files to ensure they're what you want. After confirming, click 'Recover' and choose a new location to store your recovered files.

preview files to recover
Free Download

For Windows Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

Beyond Wondershare, you can explore many other options when looking to recover deleted files in Linux. However, Recoverit saves you time.

Summing Up

This guide taught us how to delete files in the Ubuntu Linux system using GUI and the Terminal. Since storage space plays a big part in keeping your system in the best condition, these methods will help you delete unwanted files easily. You can also recover deleted files from Ubuntu using Wondershare Recoverit if needed.

You May Also Like

How To Remove Files or Directories Recursively in Linux

Here are the steps to recursively remove files or directories/folders in Linux

How To Use Foremost to Recover Files on Linux and Its Alternative

Here’s how to install and use Foremost to recover data in Linux and its best alternative.

How To Install and Use TestDisk on Linux and Its Alternative

Detailed here are the ways to install and use the TestDisk Linux data recovery tool, plus its alternative.

Top 10 Linux Partition Recovery Tools

Restore your deleted or lost data with the 10 best Linux partition recovery software.

How to Wipe Your Disk in Linux?

Linux wipe disk is necessary when you’re facing storage issues. Users can check the disk space status in Linux and wipe Linux hard drive.