The Linux shell does not print up-to-date information when it comes to ls. For example I use my other processes (IDEs etc) to create some directories. However when I run an ls command I don't see these directories. It normally takes a few seconds sometimes minutes for that directory to appear in the ls output.

What is happening? Can I force a refresh? Ideally when I say "ls" I want to see the status when I typed the command not some cached result.

The file system is not an NFS share. The only other thing I can think of is the directory was created by a program when run from Eclipse (and the display was routed to my local windows box)

I don't know how this can affect things though?

| improve this question | | | | |
  • It's a long shot, but are you absolutely sure that the directory is created on-disk by the time you run ls? Also, have you tried \/bin/ls rather than just ls, to rule out any shell builtins or aliasing issues? – a CVn Mar 4 '13 at 15:20
  • Unlikely, on what filesystem are you running ls? – daisy Mar 4 '13 at 15:26
  • Mmmm it is definitely not consistently reproducible. I am going to use /bin/ls henceforth. @warl0ck I do not understand what your question means? I am running ls on a standard bash shell. – Calm Storm Mar 4 '13 at 15:44

ls has nothing to do with bash or any shell. It lists the content of a directory, excluding hidden files (those whose name starts with a .) by requesting that list from the kernel

If ls doesn't show them, then they're not there (as far as the OS is concerned) or you're listing the wrong directory.

That can happen for instance when the current directory has been renamed under your feet. Like:

$ pwd
$ ls
$ mv /tmp/1 /tmp/2
$ pwd
/tmp/1 # (/tmp/1 has been renamed but the shell is not aware of it)
$ mkdir /tmp/1
$ touch /tmp/1/y
$ pwd
$ ls  # (ls is still listing `.` which has not changed, but now is a hardlink to `/tmp/2`, while `/tmp/1` is some new directory)
$ pwd -P  # (double check what the current directory is)
$ cd /tmp/1
$ ls
| improve this answer | | | | |
  • 2
    Aah you are right my application has moved the directory and created an empty directory in it's place. Sorry my bad. – Calm Storm Mar 4 '13 at 15:57
  • I have an even harder to catch scenario - cd into a dir, init (scaffold) some project in it and ls doesn't show anything - the dir is being replaced on copy by the template project. pwd shows the correct path, but ls doesn't show anything. cd out-and-in-again and ls will show everything. That's not an option for my users (I will copy the template's content instead of the whole dir). :) Thanks for the answer. – Nikolay Tsenkov Aug 30 '14 at 18:12

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.