29 C
Texas

How to delete a file in Ubuntu 24.04

Deleting or removing a file is a basic operation in the daily life of system administrators and mastering it is necessary. Deleting unnecessary files saves space and keeps your hard disk clean and clear. Searching and sorting becomes easier.  

You must be careful while deleting a file because once a file is deleted it is hard to recover its content.

In this quick guide, we will demonstrate to you the methods of deleting files in Ubuntu 24.04. Let’s continue without wasting any further time.

How to delete a file in Ubuntu 24.04

Open up the terminal from Show Apps or by using the shortcut key CTRL + ALT + T.

Method 1. Using rm command

- Advertisement -

One of the simplest methods of removing files is by using rm command. In reality, the rm command looks like.

rm filename

If you want to delete multiple files, the command should be written on the terminal as follows.

rm filename1 filename2 filename3

Examples

Suppose the file you want to delete is new_linux_world.txt and it is located in your current directory, execute the below command.

rm new_linux_world.txt

Similarly, you can delete multiple files by specifying the file names with rm command. 

Suppose, there are two files new_linux_world.txt and old_linux_world.txt you want to delete. The command should look like this.

rm new_linux_world.txt old_linux_world.txt

Method 2: Using unlink command

Unlink command can also be used to delete files in Ubuntu 24.04. However, it is less handy as compared to rm command because it cannot delete multiple files. The syntax of the unlink command looks as follows.

unlink filename

Example

For the sake of understanding, let’s delete a file new_linux_world.txt placed in your current directory. Execute the following command on the terminal.

unlink new_linux_world.txt

Method 3. Using shred command

When you remove a file with the rm command, the file is still recoverable. But when you use the shred command, the file is overwritten multiple times with random data and becomes unrecoverable.

Example

To delete a file new_linux_world.txt with the shred command, type the following on the terminal. Assuming your file is kept in your current working directory.

shred new_linux_world.txt

Conclusion

So, you have read the different methods to delete your file in Ubuntu 24.04. Depending on your requirements, you can use rm, unlink, and shred commands. Although they all do the same task, they have little difference.

More info:

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article