0

How can i combine both of the below commands? I want to get a single file with the owner and the size of the files

find /test -type f -size +$(df -k /test| awk 'NR == 3 { printf "%d", 
$1/4 }') -exec du -sh {} +


find /test -type f -size +$(df -k /test | awk 'NR == 3 { printf "%d", 
$1/4 }') -exec stat -c '%U' {} +
  • What would your desired output look like? – Jeff Schaller Oct 30 '18 at 0:17
  • should list size of the files and owner – Vas Oct 30 '18 at 0:21
  • ... and the filename, corresponding with the du command? Just curious if the size & filename should come first, or the owner – Jeff Schaller Oct 30 '18 at 0:22
  • yes. order should really matter. – Vas Oct 30 '18 at 0:23
  • file owner size – Vas Oct 30 '18 at 0:24
1

Two possible options, where I've pruned out the bulk of your find statement so that it focuses on the different ways to combine them:

  1. combine the find statements into a "find-shell":

    find ... -exec sh -c 'printf "%s - %s - %s\n" "$1" "$(stat -c %U "$1")" "$(du -sh "$1")"' find-sh {} \;
    

This passes the files one at a time into the shell command, which combines the stat and du commands into a formatted printf statement. This second option passes multiple files at a time to the stat command.

  1. combine the functionality with stat:

    find ... -exec stat -c '%n %U %s' {} +
    

The stat option prints the size in bytes, which is slightly different from the du -h format.


A third option exists, if you have GNU find available, for its -printf extension:

find ... -printf '%p %u %s\n'
  • Thanks Jeff. trying to include one more find here, Can you advice on how I can do that? find ..... -exec printf "%s\n" "$(awk -F '=' '/ID/ { print $2}' "$1")"' find-sh {} \; Basically this is grepping for ID from the same file which is in the form ID=0000 – Vas Nov 6 '18 at 21:09
  • The comment formatting makes it hard to interpret what's going on; I'd suggest a new question that explains exactly what you're going for and where you are now. – Jeff Schaller Nov 6 '18 at 21:26
  • I did post a new question . Here is the link unix.stackexchange.com/questions/480204/… – Vas Nov 6 '18 at 21:27

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.