Remove old files unix script


















Greg Greg 1. This will not work with files with spaces in them. You can use a while loop instead which should take care of files with spaces. Neeraj Mhatre Neeraj Mhatre 1. The OP asked "I want to delete all the files older than 15 days", which your answer doesn't provide.

They also did not ask for a restriction to php files. If that is your blogspot page, please indicate ownership explicitly, instead of the generic "below link", otherwise you become suspect of simply spamming your site. Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 1. Related 1. Hot Network Questions.

My current non-working solution is below. Any ideas, anyone?? Script to delete files. I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell I have directories named: 0 - which should contain files named 0 - But some of these directories contain file whose names are greater than and I need to delete those.

I wrote the script below but that doesnt work. Any ideas? RedHat Commands. OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands. Full Man Repository. Advanced Search. Contact Us. Forum Rules. Be VERY careful to supply an absolute path on commands like these! Once, using a command very much like this in a cron job, I accidentally deleted every file on my production mail server older than 10 days, which I can tell you was no fun to recover from. DSimon Thanks for sharing your horror story to help us avoid our own!

I had a few directories to do this to, so inspired by your comment, inside my for a in Show 5 more comments. Just spicing up the shell script above to delete older files but with logging and calculation of elapsed time!

MarcoZen MarcoZen 1, 18 18 silver badges 26 26 bronze badges. Hi MarcoZen. Why does it create three log files with the first two having no content and the last file having the list of files deleted.

What can I do so that the find and delete command doesn't generate multiple files? FokwaBest - Could be you created anoher log file? Are u using the above code fully? Can u pastebin for me to check? After removing this part, everything is written to one file. FokwaBest - Interesting I dont have that problem.. Good that u have solved it. I think you are calling this script several times?

To the anonymous editor : Which version if find has a -rm-rf option?



0コメント

  • 1000 / 1000