Show ls File Sizes with Commas
This page answers questions like these:
- How to see ls file sizes with commas?
- How to see ls with a thousands separator?
- How to see ls -l file sizes with a thousands separator?
Related Links:
File Size in Bytes using a Shell Command
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Join Lines of Text File Together
Output Lines of a File in Reverse Order
Output the Lines Between Two Matching Lines
Show ls File Sizes with Commas – Modern Solution:
ls -l --block-size="'1"
OR
LC_NUMERIC=en_US.UTF-8 ls -l --block-size="'1"
OR
LC_ALL=en_US.UTF-8 ls -l --block-size="'1"
OR
LC_ALL=en_US.UTF-8 BLOCK_SIZE="'1" ls -l
OR
export LC_ALL=en_US.UTF-8
export BLOCK_SIZE="'1"
ls -l
- On modern versions of Linux/Unix, you can use one of these commands.
- Pros: Fast.
- Cons: May not work on some versions of Linux/Unix.
Show ls File Sizes with Commas – Old-Fashioned Solution:
ls -l |
sed -e 's/\( [0-9 ][0-9 ][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/ \1/' \
-e 's/\([0-9]\)\([0-9][0-9][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/\1,\2/' \
-e 's/\( [0-9 ][0-9 ][0-9 ][ ,][0-9 ][0-9 ][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/ \1/' \
-e 's/\([0-9]\)\([0-9][0-9][0-9],[0-9][0-9][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/\1,\2/' \
-e 's/\( [0-9 ][0-9 ][0-9 ][ ,][0-9 ][0-9 ][0-9 ][ ,][0-9 ][0-9 ][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/ \1/' \
-e 's/\([0-9]\)\([0-9][0-9][0-9],[0-9][0-9][0-9],[0-9][0-9][0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/\1,\2/' \
-e 's/ \([^ ]*[0-9] [JFMASOND][aepuco][bcgrlnptvy] \)/\1/'
- On older versions of Linux and Unix, you can use this command.
- The “[JFMASOND][aepuco][bcgrlnptvy]” pattern is used to match the standard 3-letter English month abbreviations, to reduce the chance of a bad match when ls shows the date differently for files more than 12 months old.
- You can alter the “[JFMASOND][aepuco][bcgrlnptvy]” pattern to handle languages other than English.
- You can alter the “\1,\2” pattern to use a different thousands separator.
- The last line of the sed command removes spaces to help cope with the fact that commas have been added. This may cause small and large file sizes to not align vertically.
- Pros: Works on all Unix/Linux systems. Handles file sizes up to 999,999,999,999 bytes.
- Cons: Slow. Large file sizes may not align correctly.
Related Links:
File Size in Bytes using a Shell Command
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Join Lines of Text File Together
Output Lines of a File in Reverse Order
Output the Lines Between Two Matching Lines
Home > Linux / Unix > Show ls File Sizes with Commas
Tags: ls with commas, file size with commas, filesize with commas, file size commas, filesize commas, ls filesize commas, ls file size commas, show commas in ls, ls -l, thousands separator, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
file-size-with-commas-in-ls.txt
Linux-Unix/ls-file-size-with-commas.htm
2