Ubuntu: Why does the ls command show deleted files?



Question:

When I type ls in the terminal, it shows the files that are present as well as the files that I have deleted. How can I see the current files only, and why does ls keep a record of deleted files?

ls shows the deleted file names followed by a tilde (~).


Solution:1

You may use

printf '%s\n' *    echo *    ls -U  

any one of those instead of ls reference here

The ~ symbol may runtime cache or backup files.For that refer here

I edited this after seeing your comment;use this command to delete those backup files (files with ~ symbol)

find ./ -name '*~' | xargs rm  


Solution:2

ls does not cache file names. It really does show you exactly what is currently on the file system. However, as @Ravan hinted, there may be similarly named files in your directory. These are typically runtime caches or lock files created by programs such as Vim and Emacs, but could be pretty much anything. For example, if I do the following in one terminal:

$ touch foo  $ vim foo  

Then I'll see the following in another terminal:

$ ls -A  foo  .foo.swp  

.foo.swp is a hidden temporary file which will be deleted if Vim exits nicely.

Such files can be safely deleted if they are left around from earlier editing sessions which are no longer open. Just make sure you quote the file names, since they may contain special characters like tilde (~):

$ rm '.foo~'  


Solution:3

The name followed by "~" is actually a cache file. When you delete the file it may still remain as an hidden file for the nautilus but the "ls" command will show them.

Run rm *~ to remove those files.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »