Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Using "Find" & Storing To Multiple Variables

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago
alphekka alphekka is offline
Registered User
 
Join Date: May 2017
Last Activity: 14 May 2017, 1:37 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Linux 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:

Code:
./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:

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

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

Code:
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!
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 29 May 2017, 4:14 AM EDT
Location: San Jose, CA, USA
Posts: 10,309
Thanks: 521
Thanked 3,587 Times in 3,055 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
alphekka alphekka is offline
Registered User
 
Join Date: May 2017
Last Activity: 14 May 2017, 1:37 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, I thought that was where I was posting. I'll repost there soon. Thank you!
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find lines with "A" then change "E" to "X" same line nightwatchrenba Shell Programming and Scripting 10 08-28-2013 05:00 AM
Find out if multiple files have lines ending with"r" newbie2010 Shell Programming and Scripting 2 08-19-2013 10:51 AM
Using a single "find" cmd to search for multiple file types and output individual files swaters Shell Programming and Scripting 3 07-02-2013 02:19 PM
Using the "find" command to look for multiple UID's westmoreland UNIX for Dummies Questions & Answers 15 04-03-2013 05:11 AM
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 11:23 AM



All times are GMT -4. The time now is 07:45 AM.