Out of Inodes

My Linode has been running without incident for almost a year now, but recently I've been running out of inodes.

No substantial amount of hosted files have been added in several months. I can't seem to locate any directories (/tmp, etc) that are full of tiny, unused files.

Anyone out there run into this before? Anyone have tips on what may be safe to delete?

I can't fathom why I'm running out now because there have only been a few files added in recent months. The server hosts a forum, image gallery, and wordpress.

I'm not a linux expert, so if I've left out pertinent information let me know!

Thanks.

15 Replies

Over 900,000 files are in /var/lib/php5. It is so large, that performing any operations on it seem to take forever (or never seem to return)…

Dunno if that helps.

That is most likely your problem.

What are these files that are in there? If I were to take a guess, I would say that you have old session files that have built up in the "session" folder. For whatever reason they never got removed.

These files are safe to delete, so if you can't get into that folder to do work on it, just do rm /var/lib/php5/session/* from a different folder and see how long it takes to remove. If it takes a year and a half, then you know that was most likely your problem.

Your next step is then to figure out why your session files are not being cleaned up by php.

@arjones85:

rm * /var/lib/php5/session/ from a different folder
I hope people think before they copy and paste this one.

@Stever:

@arjones85:

rm /var/lib/php5/session/* from a different folder
I hope people think before they copy and paste this one.

? What exactly is wrong with that command?

Do tell please.

In my /var/lib/php/session/ folder it contains nothing but session files. So I am running under the assumption that his folder is the same.

@arjones85:

@Stever:

@arjones85:

rm * /var/lib/php5/session/ from a different folder
I hope people think before they copy and paste this one.

? What exactly is wrong with that command?

Do tell please.

In my /var/lib/php/session/ folder it contains nothing but session files. So I am running under the assumption that his folder is the same.

Follow the instructions for yourself:

cd /etc (The "from another directory" part)

rm * /var/lib/php5/session/ (the given command)

Wait, why is my /etc empty?

For those of you who are slow, "rm *" will delete the contents of the current directory…

Oops :oops: Bad typo. Fixed. I haven't had my coffee yet.

There was no -f flag so at least you still got fair warning you weren't doing what you intended to do.

:shock:

@arjones85:

Oops :oops: Bad typo. Fixed. I haven't had my coffee yet.

There was no -f flag so at least you still got fair warning you weren't doing what you intended to do.

:shock:

I don't believe you'd get much of a warning if you were root, until it tried to delete a directory. And by then…

Yeah, I suppose you're right :oops: I forget that there's no alias to rm -i by default.

@Guspaz:

@arjones85:

Oops :oops: Bad typo. Fixed. I haven't had my coffee yet.

There was no -f flag so at least you still got fair warning you weren't doing what you intended to do.

:shock:

I don't believe you'd get much of a warning if you were root, until it tried to delete a directory. And by then…
zsh will warn by default, if you have privileges.

Oops! Bad typo!

In a directory with a large amount of files, rm may not be able to cope (complains about argument list too long, a limitation of the shell I believe). Try this one (in the correct directory of course):

find . -name "*" -print | xargs rm -v

@jonny5alive:

find . -name "*" -print | xargs rm -v

At the risk of starting a command improvement match, I would personally do:

find /var/lib/php5/session | xargs rm -v

The '-name '*' -print' portion in not necessary since find with no other arguments will print all items on the specified path. If you want to be safe then you might do:

find /var/lib/php5/session -print0 | xargs -0 rm -v

The -print0 and -0 arguments are to make find print the list as 0-terminated strings, and for xargs to parse them as so. This gets around issues with filenames with spaces in them, or worse, filenames with newlines in them, a potential security risk.

edit: find's docs about file name handling.

Why all the gyrations?

find /wherever -delete

If you have tmpwatch installed, then you could edit /etc/cron.daily/tmpwatch and add:

if [ -d "/var/lib/php5/session" ]; then
    /usr/sbin/tmpwatch 24 /var/lib/php5/session
fi

Which (on a daily basis) will remove all session files that haven't been accessed in 24 hours. Adjust to your liking….

I'm not sure if tmpwatch will run into the same constraints as "rm" will when dealing with a huge number of files, but once you have the directory under control this is a way to ensure it doesn't happen again.

Well, deleting the contents of the directory will not really be good enough. The problem is that the directory itself is probably several MB big. Do "ls -l /var/lib/php5" to see how much space the directory listing is using. You don't want to leave all that space allocated.

mv /var/lib/php5/session /var/lib/php5/session.old

mkdir /var/lib/php5/session

chmod 777 /var/lib/php5/session

chmod +t /var/lib/php5/session

rm -r /var/lib/php5/session.old

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct