Delete and Remove Files on Ubuntu 22.04 Example

10-Feb-2023

.

Admin

Delete and Remove Files on Ubuntu 22.04 Example

Hi Guys,

Today, I will let you know example of Using Terminal to Delete and Remove Files on Ubuntu 22.04. I explained simply step by step Step by Step to Delete Files on Ubuntu 22.04. This article will give you simple example of Using Command to removes files on Ubuntu 22.04. you can see How to Delete Files on Ubuntu 22.04?.

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