开发者

Create a shell script that reads folders in a specific folder and outputs their size and name to a file

Would like to create 开发者_开发技巧a shell script that will read the contents of a folder that contains many folders on a server- it should output a list of these folders with their size and date modified if possible.


If you want to do it recursively (it's not clear to me from the question whether or not you do), you can do:

$ find /path/to/dir -type d -exec stat -c '%n: %s: %y' {} \;

(If you have a find which supports the feature, you can replace '\;' with '+')

Note that the %s gives the size of the directory, which is not the number of files in the directory, nor is it the disk usage of the files in the directory.


ls -l /path/to/folder | grep ^d


Try this find command to list sub-directories and their size (since stat command doesn't run same way on mac and Linux):

#!/bin/bash
find /your/base/dir -type d -exec du -k {} \; > sizes.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜