Summary
What command can I run in a bash script that will make the next ls
at a
terminal list the files in a directory immediately, instead of having to wait 10
seconds?
And see Questions 1 and 2 at end of "Full Details".
Full Details
I've got 700 video files (mp4) in a directory, ranging in size from 100 MB to 1GB. The average file size is 200 MB.
When I list them for the first time after boot (using ls in a terminal, or using pcmanfm), it takes 10 seconds before the files are listed. Thereafter, when I list them again (with ls or in pcmanfm), the files are listed almost immediately.
So to try and get round this initial wait time, I ran the following command in a script after bootup:
ls /path/to/vid-directory
... so that thereafter, when I list the directory with ls or in pcmanfm, the files list immediately.
But strangely, running
ls /path/to/vid-directory
in the SCRIPT does NOT cause the NEXT ls or pcmanfm to list the files immediately (they're listed after 10 seconds). Also strangely, when the initial script runs, the files are listed almost immediately.
So, running ls at a terminal seems to store the filenames in RAM cache, whereas running ls in a script does not*.
Question 1: Why is the latter* happening?
Question 2: What command(s) should I run in my script that WILL cause the next ls or pcmanfm to list the files immediately?
PS: Whilst doing the testing, I made sure that RAM was initially empty by running
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
ls -lR
about 1000 files a second.ls
listing ~1000 files/second from a USB 3 spinning HDD (~6000 files, ~500GB in total).