shell获取文件大小
My first goal when coding is usually to make it work and then clean up the code into a more maintainable format. Many people prefer to keep code clean from start to finish but thinking "maintenance first" slows me down --- I like to GO GO GO! Sometimes making code means the code size gets larger, sometimes it means getting smaller.
编写代码时,我的首要目标通常是使其工作,然后将代码整理成更易于维护的格式。 许多人更喜欢从头到尾保持代码整洁,但是认为“维护第一”会使我慢下来---我喜欢GO GO GO! 有时制作代码意味着代码大小变大,有时意味着变小。
Oftentimes when I'm trying to abstract my CSS preprocessing code (Stylus), I abstract my mixins but want end up with the exact same CSS output. What's the easiest way to check that the outcome is likely the same, without scouring the site and checking every section? Checking the output directory size. If the CSS code is the same size before and after changes, we're golden! So how do we check directory size?
通常,当我尝试抽象我CSS预处理代码(Stylus)时,我抽象了我的mixins,但希望最终得到完全相同CSS输出。 在不检查站点和检查每个部分的情况下,最简单的方法来检查结果是否可能相同? 检查输出目录大小。 如果CSS代码更改前后的大小相同,那么我们就很成功了! 那么我们如何检查目录大小?
du -s # 16075464, recursive
du -sh # 7.7G, recursive, human readable
The commands above provide the directory size in different formats. If you want to get the exact byte size of a directory, you can execute this slightly more complicated command:
上面的命令以不同的格式提供目录大小。 如果要获取目录的确切字节大小,可以执行以下稍微复杂一些的命令 :
find . -type f -exec ls -l {} \; | awk '{sum += $5} END {print sum}' # 8209358267
Of course something flukey could happen and the CSS change with the exact same size coming out, but this method isn't meant to be scientific. And remember that these commands can be used for any number of purposes!
当然,可能会出现一些问题,并且CSS会以完全相同的大小发生变化,但是这种方法并不意味着科学。 请记住,这些命令可用于多种用途!
shell获取文件大小