Using "Find" & Storing To Multiple Variables

Hello all!

I'm pretty new to bash scripting, so this should be a pretty easy question to solve.

For the last few hours, I've been creating a script that will list some of the following (based on a path I specify):

  • # of directories
  • # of files
  • # of executable files
  • files older than 365 days
  • and more...

What I need help with doing is coming up with a "find" command that will do the above items (and more) by passing over all my specified directory files ONLY ONCE.

When running my script, I'll do:

./myscriptname /home/alphekka

In my bash file, if no path is specified, then I'll return an exit code of 1.

I'm guessing I'm going to need to do something like this:

#!/bin/bash
find $1 \( -type f $variable1 \), \( -type d $variable2 \)

Then towards the end of my script I'll do:

printf "# of files: $variable1 \n"
printf "# of directories: $variable2 \n"
printf "etc.... \n"

Hopefully this'll be an easier to solve question. I appreciate any help anybody may be able to give me. Thank you most kindly in advance!

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on. And, tell us what operating system you're using. We would assume that by now you have tried the code you have shown us and know that it produces syntax errors instead of giving you the results you want. We would also hope that you have looked at the find man page (using the command man find ) to determine the correct syntax and know that the find command does not set variables to counts of selected pathnames.

If you did post homework in the main forums, please review the guidelines for posting homework and repost in the proper forum.

Sorry, I thought that was where I was posting. I'll repost there soon. Thank you!