0
[emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | xargs du -ch
5.0G    ./something
5.0G    .
5.0G    total

[emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | wc -l
0

When it got null input its calculating the whole directory size how to stop it

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • 1
    I don't think any part of your command is doing what you want it to do. This seems like an XY Problem. Can you please redo your question to ask what your goal is and I'm sure someone can help you find the correct solution. – jesse_b Nov 21 '18 at 15:01

2 Answers2

0

xargs has an option to not run if no input is given:

-r, --no-run-if-empty
  If the standard input does not contain any nonblanks, do not run
  the command.  Normally, the command is run once even if there is
  no input.  This option is a GNU extension.

So use xargs -r du -ch instead.

0

Use find with -exec:

month="Oct-2018";
find . -mindepth 1 -maxdepth 1 -newermt "01-$month -1 sec" -and -not -newermt "01-$month +1 month -1 sec" -exec du -ch {} \;

Though, somehow I believe, you want du -sh instead of du -ch.

See

pLumo
  • 22,565