Bash 파일 크기 확인

When working with Linux, it is important to have a good understanding of the file size of your Bash scripts. File size plays a crucial role in optimizing performance and storage usage. In this blog post, we will explore different methods to check the file size of Bash scripts using various Linux command-line tools.

Using the ls Command

One of the most common ways to check the file size in Linux is by using the ls command. To find the size of a Bash script, open the terminal and navigate to the directory where the script is located. Then, execute the following command:

ls -lh <script-name.sh>

This will display detailed information of the specified script, including its size in a human-readable format. The -l option provides a long listing format, while the -h option ensures the size is displayed in a more readable format (e.g., KB, MB, GB).

Using the du Command

The du command is another useful tool for checking file sizes in Linux. It provides a summary of the disk usage of a file or directory. To check the size of a Bash script, open the terminal and navigate to the script’s location. Then, run the following command:

du -h <script-name.sh>

The -h option again ensures that the size is displayed in a more human-readable format. Additionally, you can use the -s option to display a summary of the total size only, without listing individual files.

Using the stat Command

The stat command provides detailed information about a file, including file size, permissions, and timestamps. To check the size of a Bash script using stat, open the terminal and execute the following command:

stat -c "%s bytes" <script-name.sh>

This command prints the file size in bytes. If you prefer a different unit, you can modify the output format as per your preference. For example, to display the size in kilobytes, you can use %k.

Conclusion

Now you have several methods at your disposal for checking the size of Bash scripts in Linux. Whether you prefer using ls, du, or stat, these command-line tools provide valuable insights into the file size, allowing for better performance optimization and storage management. Remember to choose the method that best suits your needs and work with efficiency in your Linux environment.

Remember to regularly monitor the sizes of your Bash scripts and other files to ensure optimal disk usage and efficient system performance.