I need to get a list of all the files, along with their sizes, in Linux.
我需要在Linux中获取所有文件及其大小的列表。
the filesystem is ext4, running over USB on a machine with very little RAM
文件系统是ext4,在具有很少RAM的机器上通过USB运行
the functions I'm using are these - is there a better technique?
我正在使用的功能就是这些 - 有更好的技术吗?
a) opendir()
b) readdir()
c) stat()
I believe I'm getting hit pretty hard with the stat() call, I don't have much RAM and the HD is USB connected
我相信我在使用stat()调用时会受到很大的打击,我没有太多内存,而且HD是USB连接的
is there a way to say
有没有办法说
"give me all the files in the directory, along with the file sizes?" - my guess is that I'm getting impacted because stat() needs to go query the inode for the size, leading to lots of seeks?
“给我目录中的所有文件以及文件大小?” - 我的猜测是我受到影响因为stat()需要查询inode的大小,导致大量的搜索?
2 个解决方案
#1
0
No, not really. If you don't want to hit the disk, you would need have the inodes cached in memory. That's the tradeoff in this case.
不,不是真的。如果您不想访问磁盘,则需要将inode缓存在内存中。这是本案的权衡。
You could try tuning inode_readahead_blks
and vfs_cache_pressure
though.
您可以尝试调整inode_readahead_blks和vfs_cache_pressure。
#2
-1
Use cd
to get to the directory you want to get the size of the files and directories for, then type:
使用cd进入要获取文件和目录大小的目录,然后键入:
du -sh *
This will give you all the sizes of the files and directories. The s
gives a total for each argument, h
makes the output human readable. The *
means that it will show all the contents of that directory.
这将为您提供文件和目录的所有大小。 s给出每个参数的总和,h使输出人类可读。 *表示它将显示该目录的所有内容。
Type man du
to find out more about the du
command (q
or Ctrl-c
to exit)
输入man du以了解有关du命令的更多信息(q或Ctrl-c退出)
#1
0
No, not really. If you don't want to hit the disk, you would need have the inodes cached in memory. That's the tradeoff in this case.
不,不是真的。如果您不想访问磁盘,则需要将inode缓存在内存中。这是本案的权衡。
You could try tuning inode_readahead_blks
and vfs_cache_pressure
though.
您可以尝试调整inode_readahead_blks和vfs_cache_pressure。
#2
-1
Use cd
to get to the directory you want to get the size of the files and directories for, then type:
使用cd进入要获取文件和目录大小的目录,然后键入:
du -sh *
This will give you all the sizes of the files and directories. The s
gives a total for each argument, h
makes the output human readable. The *
means that it will show all the contents of that directory.
这将为您提供文件和目录的所有大小。 s给出每个参数的总和,h使输出人类可读。 *表示它将显示该目录的所有内容。
Type man du
to find out more about the du
command (q
or Ctrl-c
to exit)
输入man du以了解有关du命令的更多信息(q或Ctrl-c退出)