I am monitoring the new files created in a folder in linux. Every now and then I issue an "ls -ltr" in it. But I wish there was a program/script that would automatically print it, and only the latest entries. I did a short while loop to list it, but it would repeat the entries that were not new and it would keep my screen rolling up when there were no new files. I've learned about "watch", which does show what I want and refreshes every N seconds, but I don't want a ncurses interface, I'm looking for something like tail:
Summarizing: get the input, compare to a previous input, output only what is new. Something that do that doesn't sound like such an odd tool, I can see it being used for other situations also, so I would expect it to already exist, but I couldn't find anything. Suggestions?
The tail command is fast and simple. But if you want more than just following a file (e.g., scrolling and searching), then less may be the command for you. Press Shift-F. This will take you to the end of the file, and continuously display new contents.
Finding Files Modified on a Specific Date in Linux: You can use the ls command to list files including their modification date by adding the -lt flag as shown in the example below. The flag -l is used to format the output as a log. The flag -t is used to list last modified files, newer first.
The -l option signifies the long list format. This shows a lot more information presented to the user than the standard command. You will see the file permissions, the number of links, owner name, owner group, file size, time of last modification, and the file or directory name.
You can use the very handy command watch
watch -n 10 "ls -ltr"
And you will get a ls
every 10 seconds.
And if you add a tail -10
you will only get the 10 newest.
watch -n 10 "ls -ltr|tail -10"
If you have access to inotifywait
(available from the inotify-tools package if you are on Debian/Ubuntu) you could write a script like this:
#!/bin/bash
WATCH=/tmp
inotifywait -q -m -e create --format %f $WATCH | while read event
do
ls -ltr $WATCH/$event
done
This is a one-liner that won't give you the same information that ls
does, but it will print out the filename:
inotifywait -q -m -e create --format %w%f /some/directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With