سؤال

I have an app that successfully gets root access and executes 2 simple commands; cd / and du. I'm not even sure if the cd is necessary because I think that's where you end up after you su. But anyways.. running du prints out a lot of info. What I want to do is something() whenever I discover a folder with a size of zero. Am I going to have to walk through and query every folder manually, or is there some way to "listen" to the du output and act on it? I'm pretty good at scripting, but I know little about running Linux commands from an application...

FYI I'm using a slightly modified version of this example to run my commands.

Update

Here's what I have so far... du prints out something like

205244    ./data
0         ./dev

So if use du | cut -c1 | grep '0' I get a bunch of zeroes. This is good.. I think. But now that I've narrowed the list to entries with 0 in the 1st column, how would I use grep and cut to only print the path of 0-size directories?

Also, is cut -c1 going to be reliable? Could there be a case where the dir wasn't 0-size but had a leading zero in the output?

هل كانت مفيدة؟

المحلول

I suggest you to try this. Be warned: it is recursive.

find ./ -type d -empty -exec ls -ld {} \;

please manually check the output is right before attempting to apply your something() :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top