Search code examples
filecsvfindesxi

Improved find command to list files, their dir and size


I working on a cmd-line that I execute with plink from PowerShell (PowerCLI) on ESXi.

The idea is to list vmdk files (with exceptions), with their symlink (because their real folders names are IDs) and first subfolder (that'd help me finding VMDK file as it may reflect VM folder). Output is CSV format so I can easily use it in PowerShell. This is where I came so far:

find /vmfs/volumes -type l -exec find {} -name "*.vmdk" -follow \; | awk '{n=split($0,a,"/"); print a[4]";"a[5]";"a[n] }' | grep -v ".*-flat.vmdk$" | grep -v ".*delta.vmdk$" | grep -v ".*-ctk.vmdk$"

This is good for me, but I'd like to add file size as last field (VMDKFileName;Size). Size format does not really matter, I'll be able to manipulate it within my PS script.

Idk if I'm on the right way to fulfill my needs.

Do not hesitate to ask for more informations.

P.S: a one-liner command would be great as I'm using PLink, it's easier for me to use.

TIA


Solution

  • Ok, anwser is here (lots of headaches) !

    find $(find /vmfs/volumes -type l -maxdepth 1) -name "*.vmdk"  -follow -exec ls -lHd {} \; | awk '{n=split($0,a,"/"); print a[4]";"a[5]";"a[n]";"$5}' | grep -v ".*-flat.vmdk" | grep -v ".*delta.vmdk" | grep -v ".*-ctk.vmdk"