How to check the file size in Linux/Unix bash shell scripting

www.lau‮‬tturi.com
How to check the file size in Linux/Unix bash shell scripting

To check the file size in a Linux or Unix bash shell script, you can use the du command. The du command is a utility that is used to estimate the space used by a file or directory.

Here's an example of how to use the du command to check the file size in a bash shell script:

size=$(du -b /path/to/file | cut -f1)
echo "The size of the file is $size bytes"

This script will print the size of the file in bytes.

You can also use the stat command to check the file size. The stat command is a utility that is used to display information about a file or filesystem.

Here's an example of how to use the stat command to check the file size in a bash shell script:

size=$(stat -c%s /path/to/file)
echo "The size of the file is $size bytes"

This script will also print the size of the file in bytes.

Created Time:2017-10-28 21:38:59  Author:lautturi