![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple Files deletion in perl | pulkit | Shell Programming and Scripting | 1 | 02-12-2008 05:55 AM |
| conditional deletion of log files | sonali007 | UNIX for Dummies Questions & Answers | 3 | 10-03-2007 11:56 AM |
| Script for automatic deletion of trash file of mail server | crown2100bd | SUN Solaris | 1 | 09-20-2007 08:01 AM |
| Deletion of log files. | Geeta | UNIX for Dummies Questions & Answers | 1 | 06-23-2006 07:04 AM |
| Regarding deletion of old files | Chidvilas | Shell Programming and Scripting | 3 | 12-27-2005 10:05 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Script for automatic deletion of old files
Hi,
I have a folder with limited space. I do not have provisions to increase the space for this folder. So i have to delete files which are more than 1 month old automatically. But, i need to maintain the files created by 4 users and delete all the other files automatically which is more than 1 month. So my script should be like i find all the files that do not belong to the 4 users and delete them if it is more than 1 month old. Can someone help me to generate a script for this. Regards, Vivek |
|
||||
|
auto delete of files
You could probably try something like the following. However be very wary of where you run this comman due to the "-f" option of the rm command.
cd destination_directory rm -f `find * -mtime +30 | xargs ls -l | grep -v user1 | grep -v user2 | grep -v user3 | grep -v user4 | awk -F " " '{print $9}'` jerardfjay |
|
||||
|
thank you so much...
with this post i learn the power of xargs.... i make an script and maybe could be useful for you... itīs checks the size of the directory and if pass the limit, then check the oldest file and delete it... This procces is in a loop.... when the spaces fit the limits that you previusly input, the scripts stops... here is the code: #bin/bash #valor 0 es ok #valor 1 es demasiado grande . /arwebmin/variables/variables.conf estado=0 LIMIT=1 limite=$syslogsize while [ "$estado" -lt "$LIMIT" ] do size=`du $dir_incoming | cut -f 1` echo "$size" if [ $size -ge $espacio_maximo ] ; then echo "es mayor" echo "borrando: $dir_incoming$archivo" ls -tb $dir_incoming | tail -1 | xargs rm -f else echo "es menor" estado="1" fi done --------------------------------- regards!. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|