首页 > 解决方案 > 将具有最小大小的子文件夹的路径存储到变量中

问题描述

我为 bash 编写了一些代码,我需要将一组文件夹的最小大小存储在一个目录中,数据集将来自类似du.

例如

du -hd1 /path/to/dir/
    5GB /path/to/dir/1
    1GB /path/to/dir/2
    2GB /path/to/dir/3
    3GB /path/to/dir/4
    4GB /path/to/dir/5

在这种情况下,如何将 的值存储/path/to/dir/2到变量中$smallest

标签: linuxbashubuntu

解决方案


不需要awk_

du -d1 /path/to/dir | sort -n | head -1 | cut -f 2

推荐阅读