bash

How to check file sizes in a Linux terminal

In Linux, you can use the ‘ls’ command with the ‘-l’ (long format) option to display detailed information about files, including their sizes. Here’s how you can do it.

Open a terminal and navigate to the directory where the file is located (if necessary). Then, run the following command.

ls -l <filename>

Replace ‘<filename>’ with the name of the file you want to check. For example, if you want to check the size of a file named “example.txt”, you would run:

ls -l example.txt

The command will display information about the file, including its size in bytes.

If you want to display the file size in a more human-readable format, you can use the ‘-h’ (human-readable) option along with the ‘-l’ option, like this:

ls -lh <filename>

This will display the file size in a format that is easier to understand, such as kilobytes, megabytes or gigabytes depending on the file size.

If you want to check the sizes of multiple files in a directory, you can use a wildcard character ‘*’ to specify a pattern. For example, to check the sizes of all files in the current directory, you can run:

ls -l *

This will display the detailed information for all files in the directory, including their sizes.

Please remember that the ‘ls’ command shows sizes of files and not directories, please check out my other article on showing directory sizes if you would like more information. Hint it’s the ‘du’ command.