Is there any in-built Linux command to display the contents of a directory in real-time?
Is there any in-built Linux command to display the contents of a directory in real-time?Similar to the "tail -f file_name" command which displays the contents of a file in real-time.
you can do this using watch
. It is not completely real-time, but close enough (up to a tenth of a second):
watch -n0.1 ls
from the manual:
-n, --interval seconds
Specify update interval. The command will not allow quicker than 0.1 second interval, in which the smaller values are converted.
I wrote this, I hope this is what you needed. It's not a built-in Linux command
, but it uses only common programs present in most UNIX boxes.
Adjust sleep
time as needed. I would use a value of at least 2 seconds.
Use cmd="ls"
for non-recursive structure or cmd="find DIRNAME"
to search recursively. Note that in the last case, you will get a DIRNAME/
prefix to all files and directories.
echo "" | awk '{while ( 1 ) {cmd="find ."; delete b;c=0; while ( ( cmd | getline result ) > 0 ) {test=1;c++;n=0;for (i in a) {n++;if (a[i]==result) {b[c]=i; test=0; break;}} if (test) {n++;a[n]=result;b[c]=n;print "##NEW## "result }} close (cmd); for (i in a) {test=1;for (j in b) {if (b[j]==i) {test=0;break}} if (test) {print "##DELETED## "a[i]; delete a[i]}} system("sleep 5") } }'