How to Delete and Remove Files on Ubuntu 22.04?

Jul 19, 2022 . Admin

Hi Guys,

In this tutorial we will go over the demonstration of Delete and Remove Files on Ubuntu 22.04. This post will give you simple example of Ubuntu 22.04 in Delete and Remove Files. you can see Delete and Remove Files Using Terminal. it's simple example of Delete Files on Ubuntu 22.04 in terminal.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Just follow the rm and unlink command to remove the files:

1.Open the Ubuntu terminal

2.Type any one of the following command to delete a file named hello.txt in the current directory

3.rm hello.txt
OR
unlink hello.txt

Command to delete multiple files on Ubuntu Linux

Use the following command to delete the file named hello.txt, my.txt, and abc.jpg placed in the current directory:

rm hello.txt my.txt abc.jpg

If a file named hello.txt is placed in the /tmp/ directory, you can run:

rm /tmp/hello.txt
rm /tmp/hello.txt /home/html/my.txt/home/html/data/abc.jpg
To delete each file and prompt before removing

Pass the -i option to the rm command to get confirmation before attempting to remove each file:

rm -i fileNameHere
rm -i hello.txt
Use the rm command to explain what is being done with the file

Pass the -v option as follows to get verbose output on Ubuntu Linux box:

rm -v fileNameHere
rm -v cake-day.jpg
To delete all files in folder or directory in Ubuntu Linux

Use the following command with following options to delete all files in folder or directory in Ubuntu Linux:

rm -rf dir1
rm -rf /path/to/dir/
rm -rf /home/html/oldimages/
Ubuntu Linux delete file begins with a dash or hyphen

If the file or directory or folder name begins with a dash, use the following syntax:

rm -- -fileNameHere
rm -- --fileNameHere
rm -rf --DirectoryNameHere
rm ./-file
rm -rf ./--DirectoryNameHere
Do not run ‘rm -rf /‘ command as an administrator/root or normal Ubuntu Linux user

If run by an administrator, will cause the contents of every writable mounted filesystem on the computer to be deleted. Do not try these commands on Ubuntu Linux:

rm -rf /
rm -rf *
#Ubuntu