Argument list too long? Deleting the file or directory using its inode number

We've noticed that sometimes a file or directory has a really big size due to which removing it is not possible
and you get the message below:-

Argument list too long \*

This issue certainly happens with everyone and especially with the folder "Session", where all the sessions of the server in a directory are kept. Recently I've faced this issue on an Linux server where the user stores the server's sessions files at the location below:-

[[email protected]]# pwd
 /var/lib/sessions
[[email protected] lib]# cd /var/lib/
[[email protected] lib]# ls -al
drwxrwxrwx.  4 root  root  32875698 Nov 22 15:20 session

And I tried every possible way to remove the files inside it with the following commands:-

rm -rf session/*                                                    (remove all files inside the session directory)
find session/ -type f -name "*.sess" -exec rm {} ;      (removing files whose names end as .sess)
find session/* -mtime +50 -exec rm {} \;                 (removing files 50 days old)

But all give the same output as below after 1 hour:-

Argument list too long \*

At last, I tried the way which did remove the directory very quickly for me. I used the help of its inode number.

Step 1: Check the inode number of the directory using the command below:-

[[email protected] lib]# ls -li

1179686 drwxrwxrwx. 4 root  root  32875698 Nov 22 15:20 session

Above the first number, i.e. 1179686, is the inode of the directory session. Now remove the directory using the inode number with the command below:-

[[email protected] lib]# find . -inum 1179686 -exec rm -rf {} \;

"No such file or directory."

And that's it! The directory will be removed and after a few seconds you'll get the message as above. That's all!

Sachin Monday 03 February 2014 - 10:18 pm | | Default

No comments

(optional field)
(optional field)

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.