Script to find the files and delete them


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to find the files and delete them
# 1  
Old 02-10-2012
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.
# 2  
Old 02-10-2012
Have a look at the find command. Assuming that your users' home directories are all in /home, you could try:-
Code:
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:-
Code:
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
# 3  
Old 02-16-2012
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
# 4  
Old 02-16-2012
hello 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
# 5  
Old 02-16-2012
Can you copy and paste the command entry and output to this thread along with other useful info such as the output from:-
Code:
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
# 6  
Old 02-16-2012
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

Code:
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Find command to delete the files

Hi All, I've created 2 files touch -t 201309101234 aa10 touch -t 201309111234 aa11 Exact 60 days before from today date is SEPT 12th . As per the following command as i gave +60 means the files which were created before sept12th should be deleted find /etc/logs/*aa* -type f -atime +60... (5 Replies)
Discussion started by: smile689
5 Replies

3. Shell Programming and Scripting

Find modify and delete files

hi every one. one of my friends has writen this script and send it to me. this script can find files that add-delete-modify and also send an alert by email i'm not catch all part of it. can anyone explain me how this work #!/bin/bash START="a.txt" END="b.txt" DIFF="c.txt" mv ${START}... (4 Replies)
Discussion started by: nimafire
4 Replies

4. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

5. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

6. Shell Programming and Scripting

Script to find files and delete it by comparing

I have a directory where lot of "gzip" files are dropped in every 5 minutes. There is an application which will process these gzip and move it to another directory but will leave a gzip.out file with lot of output data. I need to remove all the outfiles except for the one which is being... (1 Reply)
Discussion started by: gubbu
1 Replies

7. Shell Programming and Scripting

find files for a particular date and delete

How can I delete files for a particular date ? I apologize in advance If there is solution please put the link. Thanks, (5 Replies)
Discussion started by: jville
5 Replies

8. UNIX for Dummies Questions & Answers

find and delete files

hi all , i want to find and interactively delete all the files having size greater than 20 bytes using "find" and other commands..... (8 Replies)
Discussion started by: sonu_pal
8 Replies

9. Shell Programming and Scripting

'unexpected token' error using FIND in script to delete old files

Hi, I am compete linux noob, but have managed to setup my Thecus N5500 to rsync to my N5200Pro to do automatic backups each night. The rsync script also moves any files deleted from the N5500 (and previously backed up to the N5200) to a _deleted folder on the N5200 so I can keep them for 30... (10 Replies)
Discussion started by: rpalmer68
10 Replies

10. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies
Login or Register to Ask a Question