Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8038269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:10:54+00:00 2026-06-05T03:10:54+00:00

My question is more so a question about code efficiency and simplicity than it

  • 0

My question is more so a question about code efficiency and simplicity than it is about simply completing a task. The scenario is as such: I would like to create a bash script that uses a for loop to iterate through /Users when it is in each users home directory I want it to see if two different directories exist in the style of:

for USER in /Users/*; do
    if [ -d "$USER/Library/Caches/com.spotify.Client" ]; then 
        rm -rf "$USER/Library/Caches/com.spotify.Client"

…but I need to check for multiple directories. How do I accomplish this in the most elegant way? I would like to avoid using a series of if statements but don’t know the best way to accomplish this.

Finally, I would like to use the find command to find a file, then set the result of the find (i.e. the path to the found file) to a variable and input it into another command. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:10:57+00:00Added an answer on June 5, 2026 at 3:10 am

    From what I understand of your requirements, I would nest the for loops:

    subdirs=(
        "Library/Caches/com.spotify.client"
        "some/other/subdir/"
    )
    
    for homedir in /Users/*; do
        for subdir in "${subdirs[@]}"; do
            dir="$homedir/$subdir"
            if [[ -d "$dir" ]]; then
                rm -rf "$dir"
            fi
        done
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is more a re-insurance than one directly about how to code. As
I'm not talking about making portable code. This is more a question of distribution.
My question is not about a specific code snippet but more general, so please
This question is more about guidance than actually solving my problem: I need to
A question about c++ design and efficiency... Imagine this code - Database db; class
So - highly hypothetical question and more like discussion about your coding style and
I got this in an interview question -- the question was more about what
One more question about most elegant and simple implementation of element combinations in F#.
This is kind of more generic question, isn't language-specific. More about idea and algorithm
So I'm trying to learn more about lambda expressions. I read this question on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.