File Size in Bytes using a Shell Command
This page answers questions like these:
- How to get the size of a file in a shell script?
- How to get the file size in bytes in a shell script?
Related Links:
Show ls File Sizes with Commas
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
File Size in Bytes using a Shell Command:
stat -c '%s' FILE
- Write the size in bytes of file FILE to stdout.
- Pros: Fast.
- Cons: The -c option to stat may not exist on some systems.
wc -c < FILE
- Write the size in bytes of file FILE to stdout.
- Pros: Doesn’t rely on the -c option to stat.
- Cons: Slower than stat.
ls -l FILE | awk '{print $5}'
du -b FILE | awk '{print $1}'
- These 2 choices both write the size in bytes of file FILE to stdout.
- Pros: They don’t rely on the -c option to stat.
- Cons: They’re all slower than using stat because they all involve 2 commands.
Related Links:
Show ls File Sizes with Commas
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 > File Size in Bytes using a Shell Command
Tags: file size, filesize, bytes, shell command, shell, command, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
file-size-shell-command.txt
Linux-Unix/file-size-in-bytes-shell-command.htm
1