深度阅读

How to use the `cat` command to display file size?

作者
作者
2023年08月22日
更新时间
9.96 分钟
阅读时间
0
阅读量

To display the file size using the cat command in Linux, you can use the stat command along with cat. Here’s an example:

cat example.txt | stat --printf="%s bytes\n"

This will display the size of the example.txt file in bytes. If you want to display the file size in a more human-readable format (such as kilobytes or megabytes), you can use the -c option along with the du command, like this:

cat example.txt | du -hc | tail -n 1

This will display the size of the file in a human-readable format, like “1.2K” or “3.4M”. Alternatively, you can just use the -h option with the ls command to display the file size in a human-readable format, like this:

ls -lh example.txt

This will display the file size in a format like “1.2K” or “3.4M”, along with other information about the file such as its permissions and modification time.

Note that for large files, it may take some time for the du command to calculate the file size, so be patient.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。