Anyone know how to view all the folders within an directory with size, folder/file, owner?
The only command I know of is du -hs *
But that shows all the subfolders aswell and does not show owner.
For example, I would like to get the info size, folder/file, owner of the folder/file under "/my/path/".
Any know of command which could provide me with this info?
Br Hultman
ACCEPTED]
You could try the find command:
find /my/path -maxdepth 1 -type d -printf "%u %g " -exec du -h --max-depth=0 {} \;
should locate all directories (filter -type d) one level below the starting point /my/path (option -maxdepth 1). It will then
-printf option to print owner and group, and thendu --max-depth=0 on each directory found ({}) to print the name and total size directly behind the output of the preceding -printf option, using the -exec mechanism.Here I've got a simple snippet for you
#!/usr/bin/env bash
unset fname owner size i
for f in "$@"
do
fname[i]="$f"
owner[i]=$(stat -c %U "$f")
size[i++]=$(stat -c %s "$f")
done
for i in "${!fname[@]}"
do
printf "User %s owns %s and the size is %d Kbytes\n" "${owner[i]}" "${fname[i]}" $((${size[i]} / 1024))
done
Make the script executable or run it like bash script_name [path]
chmod u+x script_name
And run it
./script_name /my/path/*