Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #200679
| From | David Wright <deblis@lionunicorn.co.uk> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: question about ls |
| Date | 2018-09-27 16:30 +0200 |
| Message-ID | <wCFsJ-4oD-3@gated-at.bofh.it> (permalink) |
| References | (4 earlier) <wC4tc-7MC-5@gated-at.bofh.it> <wC4My-881-7@gated-at.bofh.it> <wCE3D-3sh-9@gated-at.bofh.it> <wCEZH-404-1@gated-at.bofh.it> <wCF9n-4is-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu 27 Sep 2018 at 09:59:58 (-0400), Greg Wooledge wrote: > On Thu, Sep 27, 2018 at 08:53:28AM -0500, David Wright wrote: > > On Thu 27 Sep 2018 at 07:55:56 (-0500), Kent West wrote: > > > westk@westkbox:/opt$ ls -la | wc > > > 7 56 321 > > > westk@westkbox:/opt$ ls -1a | wc > > > 6 6 54 > > > > But do use 1A, not 1a, if you want to know how many items are > > in a folder, otherwise . and .. will be included in the count. > > All of the above give the wrong answers when filenames contain newlines. > Any solution that involves printing the filenames to a stream and then > trying to parse that stream to guess how many filenames are in the stream > is a non-starter -- unless of course the stream uses NUL delimiters > instead of newlines. > > Sadly, the GNU coreutils maintainers have rejected every request, even > requests with patches attached, to add a --null option to ls. So, > ls is not suited to this task. Sure, your FAQ is an invaluable resource for scripting, especially in a "hostile" environment. But I think one also needs to be aware of practical commands for use at the commandline in a benign environment. Knowing which technique is appropriate comes with experience. One has to be aware of the limitations of all the tools one uses. Just as ls has weaknesses, so does wc if misused. Most people assume that -l counts the lines in a file, but actually it counts the newlines, which matters for the last line. But here's another plug, and there are lots more goodies there too: https://mywiki.wooledge.org/BashFAQ/004 Cheers, David.
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Scribus has stopped importing PDF files Gary Dale <garyndp@gmail.com> - 2018-09-25 23:00 +0200
question about ls Long Wind <longwind2@yahoo.com> - 2018-09-26 00:30 +0200
Re: question about ls Ben Caradoc-Davies <ben@transient.nz> - 2018-09-26 00:40 +0200
Re: question about ls Long Wind <longwind2@yahoo.com> - 2018-09-26 01:00 +0200
Re: question about ls Long Wind <longwind2@yahoo.com> - 2018-09-26 01:00 +0200
Re: question about ls Ben Caradoc-Davies <ben@transient.nz> - 2018-09-26 01:20 +0200
Re: question about ls Kent West <westk@acu.edu> - 2018-09-27 15:00 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-09-27 15:20 +0200
Re: question about ls Richard Hector <richard@walnut.gen.nz> - 2018-09-28 08:00 +0200
Re: question about ls Ionel Mugurel Ciobîcă <I.M.Ciobica@gmail.com> - 2018-09-28 09:10 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-09-28 14:30 +0200
Re: question about ls Richard Hector <richard@walnut.gen.nz> - 2018-09-28 16:40 +0200
Re: question about ls Virgo Pärna <virgo.parna@mail.ee> - 2018-10-03 14:10 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-10-03 15:00 +0200
Re: question about ls David Wright <deblis@lionunicorn.co.uk> - 2018-09-27 16:00 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-09-27 16:10 +0200
Re: question about ls David Wright <deblis@lionunicorn.co.uk> - 2018-09-27 16:30 +0200
Re: question about ls Michael Stone <mstone@debian.org> - 2018-09-27 17:10 +0200
Re: question about ls <tomas@tuxteam.de> - 2018-09-28 09:00 +0200
Re: question about ls Michael Stone <mstone@debian.org> - 2018-09-28 12:50 +0200
Re: question about ls <tomas@tuxteam.de> - 2018-09-28 09:00 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-09-27 14:40 +0200
Re: question about ls Gene Heskett <gheskett@shentel.net> - 2018-09-27 17:00 +0200
Re: question about ls Greg Wooledge <wooledg@eeg.ccf.org> - 2018-09-27 17:10 +0200
Re: Scribus has stopped importing PDF files rv riveravaldez <riveravaldezmail@gmail.com> - 2018-09-28 01:40 +0200
csiph-web