4 ms·
If your pipeline is meant to count files then the bigger problem is that it counts directories too. If you have filenames with newlines you may have other - le
by lixtra 7y ago
If your pipeline is meant to count files then the bigger problem is that it counts directories too.
If you have filenames with newlines you may have other - less nasty - stuff too.
So you either get a reasonable answer in 1s (or 2s if you have short look at the output before counting). Or you spend 1h+ discussing requirements and carefully writing a program that gives a precise answer.
Things to consider:
- how to treat symlinks
- how to treat hardlinks
- what if files are added/removed to/from the directory tree while you scan
- how to react to missing read permissions
- is your regex on the whole path or just on the basename
- ...
- herpderperator 7y agoWell, in Unix, everything is a file[0], even directories. So when I mentioned filenames, this includes directories. :-) As a real-world example for those who are curious, running mkdir twice yields errno 17, EEXIST, which is "File exists"[1]: root@vbox:~# mkdir directory root@vbox:~# mkdir directory mkdir: cannot create directory ‘directory’: File exists But sure, the fast way could be mostly right, and maybe your goal is to just get it done and not get better at these tools, in which case, sure. [0] https://en.wikipedia.org/wiki/Everything_is_a_file https://en.wikipedia.org/wiki/Everything_is_a_file [1] https://elixir.bootlin.com/linux/latest/source/include/uapi/asm-generic/errno-base.h#L21 https://elixir.bootlin.com/linux/latest/source/include/uapi/...