Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi i need to know how to find number of files in a directory? is there any system calls in fedora 12.And i need to know how to perform a operation if the that count increases by one?
Please help me..
Thanks in advance...
Now, count contains the total no. of files under a directory.
Now, I think you can write your script to perform some operations based on this count variable.
hi friends, all answers relating to count the no of files, is ok. but if i write a script to do a operation every time i need to run that script to check file count. But i need a solution that it automatically detect and run that script program when count increases by one.
Thanks for help...
hi friends, all answers relating to count the no of files, is ok. but if i write a script to do a operation every time i need to run that script to check file count. But i need a solution that it automatically detect and run that script program when count increases by one.
Thanks for help...
I did not reply you yesterday assuming you need some system call to find the directories count. Now I understood you problem.
Still one thing is not clear.
Are you focusing on a single directory where files are created and count needs to be incremented by 1 when a new file is created ? OR
Are you keeping vigil on a directory tree hierarchy ?
If you want live monitoring and not a periodic check based one then inotify is the only way to go.
Whether to use a system call or inotify-tools from command line will depend on how you are designing your solution (are you using C or something like that or scripting?). In any case you will need a kernel that's recent enough and has inotify support. Anything that's not from paleolithic will fulfill that requisite.
With the inotify command line tools you could do something like:
Code:
inotifywait --monitor /tmp/ | while read foo; do echo "$foo"; done
You can monitor for specific events and then do whatever you want with "$foo" inside the loop. Check the inotifywait man page for further details, ask back when/if you have a clear idea of what exactly do you want if you need more help.
You will need to install inotify-tools, the name of the package can vary from distro to distro.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.