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 6087617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:53:25+00:00 2026-05-23T11:53:25+00:00

how would I go about finding all dirs in my working dir that contain

  • 0

how would I go about finding all dirs in my working dir that contain at least a non zero byte file using a Bash script ? This :

find . -maxdepth 1 -type d -size +1c | sort

does not seem to work

  • 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-05-23T11:53:26+00:00Added an answer on May 23, 2026 at 11:53 am

    Not sure if understanding fully. If I have ./lvl1/lvl2/file (file is non-empty) and lvl1 contains only empty files and the directory lvl2, should lvl1 appear in the output?

    I assumed you want it to. Think this works:

    find . -mindepth 2 -type f -size +0 | cut -d/ -f2 | uniq
    

    find looks in all sub-directories of working directory to see if there is a non-empty file anywhere inside of it. cut so we only see the level name of interest. uniq since it is unlikely a directory only contains 1 non-empty file.

    EDIT: biggest thing slowing it down is probably (didn’t do any tests lol) that find continues to look in a directory after finding a file of size >0 (we should be able to stop looking at this point). can call find on each subdir and then have find exit when it sees the first match.

    for DIR in `find . -mindepth 1 -maxdepth 1 -type d`; do
        find "$DIR" -type f -size +0 -print -quit
    done | cut -d/ -f2
    

    can drop call to uniq here (since there will only be 1 result for each top level dir). I don’t think doing anything to get rid of the cut will help much.

    another thing is that you might want to change that this looks at regular files with it not looking at directories or something (it will skip over a bunch of stuff). er, instead of “-type f” think about using “! -type d”

    about to fall asleep so it is entirely possible I missed something/did something stupid xD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering how someone would go about finding all the applications that
Specifically (taking a deep breath): How would you go about finding all the XML
How would you go about finding out how much memory is being used by
What would be the best way to go about finding what the active control
I would like to know how I would go about altering the HTML that
I've been reading about path-finding algorithms and I'm currently looking for one that works
given the following tables, how would I go about finding the most common ip
All, Given a code that you are not at all knowledgeable about in terms
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
Any ideas how I would go about writing a javascript method to insert an

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.