1

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

0
0

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

  • use the -printf option to print owner and group, and then
  • invoke du --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.
1
  • Thanks that was exactly what I was looking for! Appreciate it! – Hultman Apr 15 '20 at 13:41
0

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/*
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.