To get the size of a file in Ubuntu, you can use the ls
command with the -l
option to show detailed information about the file, including its size. For example:
ls -l file.txt
This will show output similar to the following:
-rw-r--r-- 1 username group 1234 Jan 01 12:34 file.txt
The number at the beginning of the line is the file’s size in bytes. You can also use the du
command to show the size of a file or directory in kilobytes (KB), megabytes (MB), or gigabytes (GB). For example:
du -h file.txt
This will show output similar to the following:
12K file.txt
The -h
option tells du
to display the sizes in “human-readable” format, which means it will use KB, MB, or GB as appropriate.
You can also use the wc
command to get the number of lines, words, and bytes in a file. For example:
wc -c file.txt
This will show output similar to the following:
1234 file.txt
The number at the beginning of the line is the number of bytes in the file.