In linux everything is considered as file, Now if I want to find only folders/directories not the files then how can i do that?

I am getting all the modified files with the following command.

find /Users/ghanshyam -type f -mmin -5 -print

My goal is to generate the log file with all the modified/access folders. Here two options are available.

  • create a module and call every time when a folder is modified (this one is bit difficult
    because I need to check particular event)

  • create a cron task that will run after every 5 minutes. cron task will execute shell
    script and generate the log entries with the modified folders.

Do you have any other option to do this task ?

  • you can print directories using -type d in place of -type f – Deepak Sep 24 '12 at 19:53

You can use find . -type d to list the directories. find command with iname option will filter out the results that is needed for you.

To get the modified files, -mmin should work perfectly. Also give a try with -mtime option. Apart from this to get the modified files under a directory, you can use dnotify program. Check this man page for usage.

Redirect the output a log file find /Users/ghanshyam -type f -mmin -5 -print > modified_log

About the options available for running your command:

  • Write a script to run the command every 5 mins with sleep interval
  • create a cron job
  • use watch command and put it in background
  • create a daemon
  • dnotify has been obsoleted by inotify.(dnotify is not present in my system) – Deepak Sep 24 '12 at 20:16
  • @Deepak Check out the man page link I gave in the answer. As mentioned by you there are other programs like inotify exists to do the job. – devav2 Sep 24 '12 at 20:31
  • Dnotify is not not present in my ubuntu neither. Your man page link doesn't show any alternatives to this program. Are there any? – s3m3n Feb 8 '13 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.