Computing.Net > Forums > Linux > Shell script to delete old files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell script to delete old files

Reply to Message Icon

Name: phani.junk1
Date: October 16, 2009 at 02:53:00 Pacific
OS: RHEL 5.1
CPU/Ram: 3GB
Product: Red hat Red hat enterprise linux as 4.0 for x86 amd64 em64t cd w/ 1 year standard subscription
Subcategory: General
Comment:

Hi

I am looking for a shell script to delete old files whenever storage limit is crossed for a folder. That would be great if anyone point me in the right direction in finding a simple way to do this?

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 16, 2009 at 09:29:31 Pacific
Reply:


I'll give you part of it: This find command files the 100 oldest files:

# untested, doesn't support files with spaces
find . -type f -print | xargs ls -ltr |head -100

To delete those files, just add this to the end of the command

|xargs rm


-1

Response Number 2
Name: UNIXy
Date: October 16, 2009 at 19:03:00 Pacific
Reply:


The best way to do this is to implement user quota. This way users won't be able to add more files once they've reached their set quota. As opposed to deleting files once they've gone over it. There's a chance you will delete that very important file that they need the most!

Anyway, this script searches, recursively, the current directory for folders that are larger than 1GB and prints them.

find ./ -type d -size +1G

This one search for folders in the current directory that are larger than 1GB without walking deeper than one level

find ./ -maxdepth 1 -type d size +1G

Feel free to get in touch if you have any question.

Regards
Joe

Fully Managed Dedicated Servers - http://www.unixy.net/?page=dedicated
joe@unixy.net


1

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Shell script to delete old files

Shell script 2 accept file/dir name www.computing.net/answers/linux/shell-script-2-accept-filedir-name/22197.html

Shell Script to rename files www.computing.net/answers/linux/shell-script-to-rename-files/28394.html

Linux file delete script www.computing.net/answers/linux/linux-file-delete-script/18252.html