Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|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? –  Michael Kjörling Mar 4 '13 at 15:20
    
Unlikely, on what filesystem are you running ls? –  warl0ck 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

1 Answer 1

up vote 12 down vote accepted

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
/tmp/1
$ ls
x
$ 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
/tmp/1
$ ls  # (ls is still listing `.` which has not changed, but now is a hardlink to `/tmp/2`, while `/tmp/1` is some new directory)
x
$ pwd -P  # (double check what the current directory is)
/tmp/2
$ cd /tmp/1
$ ls
y
share|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 at 18:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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