Linux 有內建指令可以即時顯示目錄內容嗎?

Linux 有內建指令可以即時顯示目錄內容嗎?

有沒有內建的Linux指令可以即時顯示目錄的內容?

答案1

你可以使用 來做到這一點watch。它不是完全即時的,但足夠接近(最多十分之一秒):

watch -n0.1 ls

從手冊:

-n, --interval seconds
          Specify update interval.  The command will not allow quicker than 0.1 second interval, in which the smaller values are converted.

答案2

我寫了這篇文章,希望這是你所需要的。它不是built-in Linux command,但它僅使用大多數 UNIX 機器中存在的常見程式。

sleep根據需要調整時間。我會使用至少 2 秒的值。用於cmd="ls"非遞歸結構或cmd="find DIRNAME"遞歸搜尋。請注意,在最後一種情況下,您將獲得DIRNAME/所有檔案和目錄的前綴。

 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") } }'

答案3

我知道之後就這麼簡單。

watch -d dir_name

答案4

您可以使用inotifytools及其命令列實用程式。

您可以使用inotify來監視目錄,它將傳回目錄本身以及目錄內檔案的事件。

另一個可以使用的工具是inotifywatch:

sudo inotifywatch -v -r /foo

您可以新增-rfor 來遞歸地觀看所有子目錄。然而這個解決方案不檢測新建立的文件的更改

所以另一個解決方案是使用inotifywait

inotifywait -m --format "%f" /foo

test*這是顯示所有新建立的文件內容的另一個範例/tmp

inotifywait -m --format "%f" /tmp | grep --line-buffered ^test | xargs -L1 -I% sudo cat /tmp/% 2> /dev/null

相關內容