Script to find the files and delete them

This is a real world problem so I think you might found this interesting. We have servers which are shared by multiple team members. Each team member has its own user id and home directory. Now with time each user starts creating files which in end caused the disk to be full.

Now for creating a build (something like make), some 500 MB is needed. But now anyone who has to create the buid, has to find the file and request that user to remove the files.

How does the user find the files consuming al the space?

We have been using multiple commands like df, du, find. But till now I have not find an easy and quick way to find the files which is taking up most of the disk space.

Have a look at the find command. Assuming that your users' home directories are all in /home, you could try:-

find /home -type f | xargs ls -l | sort -bn +4

This will long list off every file (assuming that the user can read all the directories) then sort them on size. Just check that the byte value is indeed in column 5 (skip 4 columns on the sort)

If it just gets too big a list, grow you command to:-

find /home -type f | xargs ls -l | sort -bn +4 | tail -50

to hopefully just get the important chunk, i.e. the largest 50 files.

Does that help?

If I've missed the point, let me know and I will think again.

Robin
Liverpool/Blackburn
UK

Rohit,

Did this do what you need? If not can you explain what we're missing and we'll see if someone can help.

Robin

i have run that cmd in ssh but i getting an errror that +4 in sort is an invalid filename ,it means the sort is not taking it as a option pls,
see what u can do in this regard or any alternate way to do this

thanks
rohit

Can you copy and paste the command entry and output to this thread along with other useful info such as the output from:-

uname -a
ps -f
id

Not sure what they may tell me, but it may give me/everyone else a pointer to think about.

Cheers,
Robin

go in the Filesystem in which you have a space issue.

Then find all the file that are 20MB or more and sort them by size

find ./ -xdev -type f -size +20000000c -ls | sort -k 7n

You can of course lower your size research criteria or change it to any value suitable for your problem.