|
|
|
|
|
by mnaydin
3430 days ago
|
|
I'd use the find command with the -printf option (GNU find has this option but POSIX find doesn't define it) instead of ls. For instance: find /path/to/dir -type f -printf "%s\n" | awk ' { s += $0 } END { print s " bytes" } ' The find command has much powerful file filtering capabilities than that of the ls command and works better with weird characters in filenames. |
|
There is also the -print0 option to find to handle filenames with newlines in them.
-print0 may be non-POSIX and a GNU extension.
POSIX has -print, but interestingly, in some Unixes I have seen that not using -print still prints the filenames found, by default.