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

  • Home
  • SEARCH
  • 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 449659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:47:29+00:00 2026-05-12T21:47:29+00:00

I often use the excellent find program in Bash to list files with certain

  • 0

I often use the excellent find program in Bash to list files with certain filters. For example, in a Subversion (SVN) working copy, I sometimes wish to recursively list all files but excluding the .svn subdirectories as follows:

find . -name '.svn' -prune -o -type f -print

Today, I wanted to do something similar, but I also wanted to affect the order in which directory contents were listed: I wanted ‘ordinary’ files to be followed by sub-directories (and then the recursive contents). There does not appear to be an option for this.

The ls (list) command has an option to list recursively. This command has many sorting options, including list by file name, access time, size, and so on, but not classification, although the -p option will annotate directories.

Now, I could write, e.g., a Python script to do exactly what I want. However, find already does almost everything I want. Usually within a Bash shell, it is possible to combine programs to do just what you want: each program, like find, sort, uniq, ls, wc, performs a simple task, but does so well. Not every program needs to be able to sort because sort can sort. So, really, I’m just curious…

My question is, do you know if there’s a way to do what I want: to both filter and sort a recursive file listing, just by combining Bash programs?

For example, find gives me the files in this, alphabetical, order:

a.txt
b\file1.txt
b\subdir\file2.txt
b\then_file3.txt
c.txt
d\file4.txt
e.txt

but I’d prefer them in this order, where within each directory, the ordinary files are listed alphabetically first, followed by the directories, again alphabetically:

a.txt
c.txt
e.txt
b\file1.txt
b\then_file3.txt
b\subdir\file2.txt
d\file4.txt

(I am a Windows user, but I run a Bash shell in Cygwin.)

Thanks.

  • 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-12T21:47:29+00:00Added an answer on May 12, 2026 at 9:47 pm

    Use an embedded find. The outer find locates all directories and executes an inner find which shows just the files you want in that directory:

    find . -type d -exec find {} -type f -maxdepth 1 \;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Looks like you never new up your Rows variable. Rows… May 12, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer How about just the following? test.GetType().Name.Split('\'')[0] It works on non-generic… May 12, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer The OVER clause should give you what you want. From… May 12, 2026 at 10:53 pm

Related Questions

I find this excellent code, posted by aemkei as answers to this questions: How
I often find myself implementing a class maintaining some kind of own status property
I'm working on a web application for which I'm attempting to implement a full
I've been reading up on branching/merging with Subversion 1.5 using the excellent and free

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.