Timeline for What's the POSIX-compliant way to get the size of a file or folder in bytes?
Current License: CC BY-SA 4.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 30, 2023 at 12:53 | comment | added | Stéphane Chazelas | @finefoot, See also What does "LC_ALL=C" do?. wc -c only works for non-directory files you have permission to read and have possible side effects for non-regular files. See also How can I get the size of a file in a bash script? | |
| May 30, 2023 at 12:27 | comment | added | finefoot | Ahh, great. That's explains it, thank you. :) I've seen LC_ALL=C quite a few times in scripts and always wanted to read about the reason why it's used. And you opted for ls compared to wc -c (see below) due to much better performance of reading the size instead of counting the length, right? | |
| May 30, 2023 at 5:06 | comment | added | Stéphane Chazelas | @finefoot, the date field is locale-dependant as well as what blank characters may be used to separate fields (though in practice, that date field appears after the field we're interested in so unless it contains newline characters, it's likely not going to be a problem, and I've not seen any ls implementation that uses blank characters other than space to separate fields). C locale in any case removes complex processing in both printing and parsing and reduces the risk of bad surprise. | |
| May 29, 2023 at 23:34 | comment | added | finefoot | Your answers are always very helpful and a great source to learn from. I am still trying to understand each line. "The output of ls -n is only specified in the C/POSIX locale." Where are you getting this information from? I had a look at the opengroup utilities/ls page | |
| May 29, 2023 at 22:55 | vote | accept | finefoot | ||
| Dec 21, 2022 at 9:27 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 11 characters in body |
| Dec 21, 2022 at 9:19 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | edited body |
| Dec 21, 2022 at 9:14 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 1122 characters in body |
| Dec 21, 2022 at 8:56 | history | answered | Stéphane Chazelas | CC BY-SA 4.0 |