LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-20-2008, 05:05 AM   #1
ratul_11
LQ Newbie
 
Registered: Dec 2005
Posts: 29

Rep: Reputation: 15
Linux directory file listing after a particular interval


Dear All

Suppose there is a directory which is being used or accessed by several users / programs to store files. Now if I want to check after a certain time interval ( say per hour) how many files are being added to this directory [ I don't need to check how many files has been deleted] then how to do this?

Thanks & Regards in advance
Anirban Adhikary
 
Old 02-20-2008, 07:01 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
I hope this isn't homework. Kinda sounds like it.

If you want to know how many more files there are than there were, have cron run this hourly - probably a better way, of course, but it may work.
Code:
find_cmd() { find DIR -type f | wc -l > file_number; }

if [ -f file_number ]; then
  mv file_number file_number.old
  find_cmd
  echo $(($(cat file_number)-$(cat file_number.old)))
else
  find_cmd
fi
If you just want to know how many files have been added, then this could work - though it'll just check timestamps - someone could 'touch' every file in the DIR and this would return every file.
Code:
if [ ! -f timestamp ]; then
    touch timestamp
fi
find DIR -type f -newer timestamp | wc -l
touch timestamp
If these aren't right, at least they might give some ideas.
 
Old 02-20-2008, 08:33 AM   #3
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
You don't need to use a timestamp file with find, it can tell you what files have been modified between two time parameters. For example:

Code:
find . -mmin +0 -mmin -60
will tell you which files or directories have been modified in the last hour. You can change the interval to match your needs.

If you are only concerned with files and not subdirectories in your count include the "-type f" parameter.

Also as noted by digiot, if a file is modified it will be included in the time period it was last modified, not when it was first added.

HTH

Forrest
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save ftp directory listing into a file Vitalie Ciubotaru Linux - Software 1 06-30-2007 06:37 PM
How to protect a file/directory in your home login directory (RH Linux) jitsenho Linux - Security 9 07-03-2006 11:08 PM
Apache Directory Listing Of NFS Mount, cannot view directory list via apache luqmana Linux - Networking 2 12-19-2005 06:03 AM
Directory Listing mattbeekler Linux - Software 8 07-22-2003 02:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration