[Klug-general] out of inodes

James Morris james at jwm-art.net
Thu Apr 29 14:10:44 UTC 2010


Ok, here's a BASH script to count files:

---------------8<-----------------
#!/bin/bash
DIR=$1

if [ "x" == "x$1" ]
then
DIR=$PWD
fi

TOTAL=0

while IFSO= read -r -d $'\0' dir; do
COUNT=0
while IFS= read -r -d $'\0' file; do
    let "COUNT += 1"
done < <(find $dir -maxdepth 1 -type f -print0)
echo "${dir} ${COUNT} files"
let "TOTAL += COUNT"
done < <(find $DIR -type d -print0)
echo "total files ${TOTAL}"
---------------8<-----------------

I've based it upon some code here:

http://stackoverflow.com/questions/1956144/bash-script-to-rename-all-files-in-a-directory/1956165#1956165

I've done a simple test and the output is like so:

gensys at gentoomus ~/Projects $ ./count boxyseq
boxyseq 45 files
boxyseq/gridtest 30 files
boxyseq/gridtest/eventlist 2 files
boxyseq/listtest 14 files
total files 91

You can specify a directory to it, or it'll use the current working
directory. It trusts what you tell it.


James.

On Thu, April 29, 2010 00:35, Stuart Brand wrote:
> in Nautilus you can browse the folders and instead of size, for folders
> it displays item count.
>
> all I can think of without writing a bash script?
>
>
> On Wed, 2010-04-28 at 10:47 +0100, Dan Attwood wrote:
>> Hi all
>>
>>
>> I've managed to run out of inodes on my /var partition. df shows the
>> partiton as 42% full 'df -i' shows it 100% full.
>>
>>
>> What's the best way of finding out the number of files in folders so
>> that I can find the one that's eating all my inodes and think about
>> deleting them?
>>
>>
>> Dan
>> _______________________________________________
>> Kent mailing list
>> Kent at mailman.lug.org.uk
>> https://mailman.lug.org.uk/mailman/listinfo/kent
>
>
>
> _______________________________________________
> Kent mailing list
> Kent at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/kent
>





More information about the Kent mailing list