How do I refresh directory in BASH?
I have a directory, containing files generated by compiler. During each rebuild this directory gets cleaned and, after build process ls
gives me empty output. After I cd
out of directory and then back to it ls works right.
The questions are:
- Is there any other, more elegant way to refresh directory?
- What actually happens when files deleted and recreated? Why do I need to
cd
to see actual directory content?
Your script is most likely removing the directory, and not just the files which are there. So, when you have cd
'd into it, and the directory is removed, you do ls
on a directory which does not actually exist.
By cd ..
and cd (directory)
you move up and back into the (newly created) directory, and the files are there as you expect.
The best alternative is instead of cd
ing in and out of the directory, is to add the directory name to your ls
command, and run it from the parent directory. So, ls YourSubdirectory
instead of just ls
.
There is even a shorter way:
cd .