Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all files with a filename that ends with tilde

Tags:

linux

I use Emacs and it sometimes makes backup for edited files. After a few days, I would have a lot of backup files whose name ends with a tilde.

Is there a way to find these files and delete them at once?

I tried this:

find "*" -type f -iname *~ 

But it doesn't work. I want the command to work recursively – something like ls -alR.

like image 746
nothing-special-here Avatar asked Sep 21 '11 14:09

nothing-special-here


People also ask

How do I search for a tilde file?

Go to the windows explorer and search with this string, on the related folder. It will give you all the tilde files unterneath this tree. Normally you can delete them all, especially if they are older.

What are files that end with a tilde?

If a file is appended with a tilde~ , it only means that it is a backup created by a text editor or similar program; it does not suggest another program is writing to that file.

What does tilde after filename mean?

Files that suddenly appear with a tilde are usually backups of a file that was opened or still opened. For example, with a file called myfile. doc, when it is opened in Microsoft Word, the ~$myfile. doc is created. It is a temporary backup file, used to recover data if the software crashes or stops unexpectedly.

How do I find a file with a certain name?

Finding files by name is probably the most common use of the find command. To find a file by its name, use the -name option followed by the name of the file you are searching for.


2 Answers

You need to escape from the shell. And you need to specify search path, not *

find . -type f -name '*~' 

To delete the files:

find . -type f -name '*~' -exec rm -f '{}' \; 
like image 51
Drakosha Avatar answered Sep 29 '22 04:09

Drakosha


You can do something like that :

find . -type f -name '*~' -delete 

If you want to delete also #*# file :

find . -type f -name '*~' -o -name '#*#' -delete 

You can print all deleted files with "-print":

find . -type f -name '*~' -delete -print 
like image 22
GaetanJUVIN Avatar answered Sep 29 '22 04:09

GaetanJUVIN