我试图打印目录中最大的文件,但我无法解释为什么我得到768而不是726491。$DIR是目录,$ext是文件扩展名。我的剧本应该用破折号。
find "${DIR}" -type f -name "*.$ext" -exec du -a {} + |
sort -n -r | head -n 1 | cut -f1
768 ./subfolder/test.jpg
-rw-r--r-- 1 username vti 726491 19 mar 12:46 test.jpg
drwxr-xr-x 2 username vti 512 19 mar 12:46 subsubfolder
drwxr-xr-x 3 username vti 512 19 mar 12:46 .
drwxr-xr-x 4 username vti 512 19 mar 12:46 ..发布于 2016-03-19 12:46:18
默认情况下,du将磁盘使用率显示为块大小(1024字节/ 512字节),而不是以字节为单位。
如果希望du打印bytes,则需要指定-b (或--bytes)选项:
find "${DIR}" -type f -name "*.$ext" -exec du -a -b {} + | ..
^^与DU(1)相关
--apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in ('sparse') files, internal fragmentation, indirect blocks, and the like -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below -b, --bytes equivalent to '--apparent-size --block-size=1'
更新
在不支持-b选项的系统上,使用-B 1选项:
find "${DIR}" -type f -name "*.$ext" -exec du -a -B 1 {} + | ..UPDATE2 In FreeBSD,您需要指定-A选项来显示明显的大小。
https://stackoverflow.com/questions/36101835
复制相似问题