One of the most asked questions about files in Linux is how can I list file sizes in different formats? In this post, we will look at different commands to get file sizes.
关于Linux中文件的最常见问题之一是如何列出不同格式的文件大小? 在本文中,我们将介绍不同的命令来获取文件大小。
ls命令 (ls Command)
ls command is a primary command to list and get information about files and directories in Linux. ls command can be used with -l parameter to get the size of files.
ls命令是用于列出和获取有关Linux中文件和目录信息的主要命令。 ls命令可与-l参数一起使用以获取文件的大小。
$ ls -l nmap-7.31.tgz
We listed file nmap-7.31.tgz file size in byte but we can make the size information more readable by using -h option.
我们以字节为单位列出了nmap-7.31.tgz文件大小,但我们可以使用-h选项使大小信息更易读。
$ ls -lh nmap-7.31.tgz
杜司令部(du Command)
du command is used to get disk usage.
du命令用于获取磁盘使用情况。
$ du nmap-7.31.tgz
We have simply listed the file without providing any parameter. Provided size is in KB. If we want to get a human-friendly result we can use the following.
我们仅列出了文件而未提供任何参数。 提供的大小以KB为单位。 如果我们想获得人类友好的结果,可以使用以下方法。
$ du -h nmap-7.31.tgz
stat命令(stat Command)
Stat command is used to get file system-related information about files and directories. Using stat with filename parameter will provide size information in byte mode too.
Stat命令用于获取有关文件和目录的文件系统相关信息。 将stat与filename参数一起使用也会以字节模式提供大小信息。
$ stat nmap-7.31.tgz