X-Recipient: archive-cygwin AT delorie DOT com X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 445D33945C1B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=SystematicSw.ab.ca Authentication-Results: sourceware.org; spf=none smtp.mailfrom=brian DOT inglis AT systematicsw DOT ab DOT ca X-Authority-Analysis: v=2.4 cv=INe8tijG c=1 sm=1 tr=0 ts=5ff6055a a=kiZT5GMN3KAWqtYcXc+/4Q==:117 a=kiZT5GMN3KAWqtYcXc+/4Q==:17 a=IkcTkHD0fZMA:10 a=94nOnFI1EgyDtX4ev68A:9 a=QEXdDO2ut3YA:10 To: cygwin AT cygwin DOT com References: From: Brian Inglis Organization: Systematic Software Subject: Re: "ls" sorts wrongly if given large number of files Message-ID: <33d9f866-0916-2287-8035-20168010faab@SystematicSw.ab.ca> Date: Wed, 6 Jan 2021 11:45:45 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-CA X-CMAE-Envelope: MS4xfAvPdBZFNXOGRSDqB4vzuSEgha17JPWOY3hAvk4gQZWq++2nNMU40VzA/Jek7JUfGkreLKM/iNl+AIRmKB7b6E17hHpz0BzPa7kC4VvEFxwEaXhFmRkj 2UeAGBKqf85X+73LC9uEzW4w4O6M3WKTI+QjFM8Cr5yl/Vfy1BrMrsni/MJ0S+nv0nCxEwdwGxjWyARVrFovl+xkzoebvly69wlHpX7C5bCl1Y/ViMMknf6O X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: cygwin AT cygwin DOT com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: cygwin-bounces AT cygwin DOT com Sender: "Cygwin" On 2021-01-06 11:17, Kamran via Cygwin wrote: > "ls" (version 8.26) sorts wrongly if given large number of files via "find" or > "xargs" > > For example: > > find -type f -exec ls -oS -h {} + > > OR > > find -type f -print0 | xargs -0r ls -oS -h > > Gives following data. Sorry for the long listing, and wrapped lines. But search > for "setup.ini" which is about 17 MB, it is sorted AFTER very small files. > > In fact it seams that sorting is restarted from that file (subsequent files are > again sorted). Note also that removing "-h" from "ls" command lines results in > the same problem. > > (output is trimmed to remove unnecessary data, i.e. perms/user/date-time, but > order is the same) Shells and programs have limited command line lengths, so the target program may be run multiple times by find or xargs, more times when the file path names are long, as fewer file path names can fit in each command line, so output line lengths from ls and numbers of files sorted together will vary. You can reduce this impact by changing to the closest common directory to your files, and using shell and ls options and features to get similar results e.g. $ ( cd .../release/; ls -hoS **/*.{tar.*z*,ini}; ) -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. [Data in binary units and prefixes, physical quantities in SI.] -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple