I tried with
find . -maxdepth 1 -type f -size 0 | xargs rm -f
but, getting the error
find: bad option -maxdepth
seems maxdepth is not there in my system. m using HP-UX
Please help.
I tried with
find . -maxdepth 1 -type f -size 0 | xargs rm -f
but, getting the error
find: bad option -maxdepth
seems maxdepth is not there in my system. m using HP-UX
Please help.
try this
find . -type f -size 0 | xargs rm -f
find . \( ! -name . -prune \) -type f -size 0c | xargs -i rm -f {} \;
I think that should do it.
Hope it helps,
Cam
If no file has space in name, you can try below command:
ls -l|awk '!/^d/&&$5==0 {print "rm ",$NF}'
After confirm, then add |sh after awk command.
ls -l|awk '!/^d/&&$5==0 {print "rm ",$NF}' |sh
ruby -e 'Dir["**/**"].each{|f| File.unlink(f) if File.size(f)==0}'
But, all of those solutions are are causing
all the 0 size files to be removed recursively from its child directories .
my requirement is to remove the 0 size files from the current directory only.
and what is the use of
|sh
could not be sure on that.
The solution from Cameron in post #3 looks sound. It just needs to lose the \; at the end of the line.
Test it first with an echo to see what commands will be executed.
find . \( ! -name . -prune \) -type f -size 0c | xargs -i echo rm -f {}
find . \( ! -name . -prune \) -type f -size 0c | xargs -i rm -f {}
the first command " ls ... |awk " will give the list that which files need be deleted (they are in current folders).
the outputs like: (only display, but not executed)
rm file1
rm file2
second command by |sh will executed the rm command.