3

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 (~).

  • 1
    Does it shows any tild(~) symbol at the end of deleted files @Vasu – Ravan Aug 23 '15 at 10:35
  • 4
    Please include the output of ls verbatim in your question (formatted as code). – l0b0 Aug 23 '15 at 10:37
  • @Ravan Yes it shows tilt symbol at the end of deleted files – Vasu Dev Garg Aug 23 '15 at 10:39
  • they are mostly back-up files created by text editors. You can view them and If you are sure you don't want them, you can delete them as well. – Ron Aug 23 '15 at 10:40
  • 1
    of course, it will. :) see linux.about.com/od/ubuntu_doc/a/ubudg10t7.htm for more – Ron Aug 23 '15 at 11:26
4

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
  • Just know I edited @Ron....OP asking to see only current files.. – Ravan Aug 23 '15 at 10:54
  • 2
    better now. find has a -delete option as well. So find ./ -name '*~' -delete will work as well. – Ron Aug 23 '15 at 10:55
  • @Ron the edit was helpful!! – Vasu Dev Garg Aug 23 '15 at 11:01
  • Is there an alternative such that the tilt(~) files that are created by the editors are not shown which are shown in ls command so that i have not to delete them? – Vasu Dev Garg Aug 23 '15 at 11:04
  • @Ravan I found that I could hide tilt files by making an alias for ls and putting it into .bashrc ..... code to put in .bashrc is alias ls="ls --ignore-backups $@" but it is not working? – Vasu Dev Garg Aug 23 '15 at 11:16
9

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~'
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.