Note that there are some explanatory texts on larger screens.

plurals
  1. POBash command to recursively list files but sorting by classification
    primarykey
    data
    text
    <p>I often use the excellent <a href="http://www.gnu.org/software/findutils/manual/html_mono/find.html" rel="noreferrer">find</a> 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 <code>.svn</code> subdirectories as follows:</p> <pre><code>find . -name '.svn' -prune -o -type f -print </code></pre> <p>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.</p> <p>The <a href="http://www.gnu.org/software/coreutils/manual/html_node/ls-invocation.html" rel="noreferrer">ls</a> (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 <code>-p</code> option will annotate directories.</p> <p>Now, I <em>could</em> write, e.g., a Python script to do exactly what I want. However, <code>find</code> 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 <code>find</code>, <code>sort</code>, <code>uniq</code>, <code>ls</code>, <code>wc</code>, performs a simple task, but does so well. Not every program needs to be able to sort because <code>sort</code> can sort. So, really, I'm just curious...</p> <p><strong>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?</strong></p> <p>For example, <code>find</code> gives me the files in this, alphabetical, order:</p> <pre><code>a.txt b\file1.txt b\subdir\file2.txt b\then_file3.txt c.txt d\file4.txt e.txt </code></pre> <p>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:</p> <pre><code>a.txt c.txt e.txt b\file1.txt b\then_file3.txt b\subdir\file2.txt d\file4.txt </code></pre> <p>(I am a Windows user, but I run a Bash shell in <a href="http://www.cygwin.com/" rel="noreferrer">Cygwin</a>.)</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload