i have to show size of all files .conf which are in /etc and redirect size output to a file.txt but i want to add to my command a flag which set a limit of redirected output

my command is:

find /etc -name "*.conf" -printf "%s\n" | paste -sd+ | bc > file.txt

but this command show 365077 bytes

and i want to have values between 120000 bytes and 300000 bytes of redirected output that means when i cat file.txt to have a value between 120000bytes and 300000bytes

How to find the flag for command?

closed as unclear what you're asking by Isaac, roaima, Jeff Schaller, RalfFriedl, Romeo Ninov Nov 17 '18 at 5:47

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Why do you need the sum to be a certain size? Or do you only want to report when the total size is in that range? – Jeff Schaller Nov 16 '18 at 19:45
  • I keep this on my toolbox du -a | sort -n > file.txt. du is faster than any other command, you can use it to list files/size – ronnie bermejo Nov 16 '18 at 19:46
  • @JeffSchaller yes i want to report the total size is a range (120k -300k bytes) – Max44 Nov 16 '18 at 19:47
  • 3
    @Jeff - sounds like a new homework assignment ... – don_crissti Nov 16 '18 at 19:49

If you want to restrict the result to sums between 120000 and 300000 bytes, then one way would be to add an awk filter at the end:

find ... | bc | awk '$1 >= 120000 && $1 <= 300000' > file.txt

This would create an empty file.txt for sums outside of the range, otherwise, the sum is sent to the file.

To create the file only if the sum is in the range:

... | awk '$1 >= 120000 && $1 <= 300000 { print $1 > "file.txt" }'

... to have awk write to the file; drop the redirection at the end.

  • this is working but also i want to have some value in file.txt but this value should be less then 300000 bytes and greater than 120000 bytes empty file is a problem can i do that? – Max44 Nov 16 '18 at 20:11
  • @Max44, see the edit; I have awk write the file only if the sum is in the range. – Jeff Schaller Nov 16 '18 at 20:16
  • this command doesn`t create the file.txt but i created with touch and after that i run entire command but when type cat file.txt there nothing in – Max44 Nov 16 '18 at 20:21
  • Well, if your result, as you showed in the question, was 365077, then that's outside the range, right? – Jeff Schaller Nov 16 '18 at 20:21
  • yes, when i run cat file.txt it show 365077 but i want to show only between 120000 and 300000 bytes – Max44 Nov 16 '18 at 20:23
$ find /etc -name \*.conf 2> /dev/null | xargs du -sc | tail -n1
1092    total

Total size of .conf files on this host the user running this command has permission to inspect is 1092 bytes.

  • i want to redirect output to a specific file.txt and after that when i try cat file.txt to display values between 120k 300k bytes – Max44 Nov 16 '18 at 19:58
  • That seems trivial enough. Edit your question to show this, and what you have tried, and how it did not work as expected or intended. – DopeGhoti Nov 16 '18 at 19:59
  • i did it check description – Max44 Nov 16 '18 at 19:59

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