L
L
lagudal2021-10-06 16:51:03
bash
lagudal, 2021-10-06 16:51:03

Is it possible to add the size of the found to the search results output to a file?

In fact, now on Mac, I don’t know if there is a fundamental difference with Linux in this matter.
For example, I want to find all files and folders log and logs without case sensitivity, i.e. there is log, Log, logs Logs (I don't want to choose by "log*" because a lot of unnecessary things will fly out, logo for example).
I just search with -o and output the results to a file.

sudo find / -iname "log" -o -iname "logs" > logs.txt

And still there is a lot of this in the system, is it possible to add a size to each found position? Well, the output to the file would be something like this:
/Users/user/logs 20K
/Users/user/gits/base/.git/logs 10K
/Users/user/Documents/Library/Logs 200M

Well, or something like that.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hint000, 2021-10-06
@lagudal

it'll do?:

sudo find / -iname "log" -o -iname "logs" | xargs -l1 du -s > logs.txt

or even so
sudo find / -iname "log" -o -iname "logs" | xargs -l1 du -s | sort -g > logs.txt

P
pfg21, 2021-10-06
@pfg21

find / -iname "log" -printf "%f %s\r\n"
man find
if it doesn't work, run ls with the required output format via -exec.

S
Saboteur, 2021-10-06
@saboteur_kiev

Use find and stat. You can use stat to look at all the attributes of a file:

sudo find / -iname "log" -o -iname "logs" -exec stat -c "%n %s" {} \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question