Sponsored Content
Full Discussion: UNIX Script to clean files
Top Forums UNIX for Beginners Questions & Answers UNIX Script to clean files Post 303033053 by bakunin on Friday 29th of March 2019 07:12:03 AM
Old 03-29-2019
First off, welcome to the forum as well as the family of the most powerful OSes there is in the world. You will find that Unix - any Unix, including Linux - is a set of finely tuned tools, just like an orchestra is a set of highly trained musicians. Let the right conductor - you - step up and they will blow the audience away.

Quote:
Originally Posted by wert468
I need a script that would delete files which are more than "X" number of days old
Let us start right here, at your premise. In UNIX every file has not one but several timestamps. There is:

- creation time
- modification time
- access time

and they are all set independently. You open a text editor and write a new file. All three of these times are set. After some time you open the file in a text editor again and change something - only the modification time and the access time (because to change it you need to read it first) is changed. Some time after this you display the files contents - only the access time is updated.

Also notice that many files on a UNIX system are important or even vital even if they are NOT updated regularly. I.e. the configuration file for a web server is being read when the web server starts, so its access time may be 2 months past if it runs for 2 months. You still shouldn't delete it, though, if you want to be able to start the webserver again. (notice that UNIX systems running for months or even years is - unlike Windows systems - rather normal. I have actually customers complain to me if i want to restart their server once a year after some major OS update. "You restarted already last year, why now again?" - no, i do NOT exaggerate here, i heard, word for word, exactly this complaint. In the OS i work with the most - AIX, IBMs UNIX - it is even possible to do OS and kernel updates under load with no interruption of the service. For exactly these situations where customers complain about the necessity reboot once a year or every other year.)

On the other hand, UNIX systems do not have "drives" but only one (uniform treelike) filesystem. So you may identify one or several branches in this tree where you want to start the cleaning operation and leave alone all the others.

In light of this you might want to rethink and restate your goals and we can discuss what might be done then.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

clean up script

I have a script which would monitor a given directory and delete any files which are older than 10 days. I was going to set the 10 crob jobs to perform this operation for 10 different directories (some are actually sub-directories), but my boss doesn't like that idea, so I need to do that in one... (1 Reply)
Discussion started by: mpang_
1 Replies

2. OS X (Apple)

Startup script to clean out trash can

I need to know how I would be able to clean out the trash can of a single "dumb" user every time the MAC is turned on. Back ground. OS 10.3x G3 Mac Two users configured... 1) Root or Admin (superuser) 2) student (Simple no access to anything but shared folder for files etc.) The problem... (4 Replies)
Discussion started by: Andrek
4 Replies

3. Shell Programming and Scripting

Space Clean Up Activity In Unix

Hi I am trying to develop a script so that whenever used % reaches 90% it will send an alert mail. Following is the script whic I am tryiing to implement but it show some error. code: #! /bin/ksh df -v | grep -i "/opt" | awk '{print $6}' > space if ] then echo "ALERT YOUR SPACE IS TOO... (6 Replies)
Discussion started by: pankajkrmishra
6 Replies

4. Shell Programming and Scripting

Clean old log files

Hi, I want to remove old log files (more than 7 days log files), rest of the logs should be present on my Linux box. could some one please give me any thoughts. Thanks. (3 Replies)
Discussion started by: marmam
3 Replies

5. Shell Programming and Scripting

How to clean this script?

Hello guys, this script partially works but it's still pretty ugly and, moreover, if the month is jan/feb/mar... it doesn't work at all. Could anyone say me how to correct, cut and clean a little bit? #!/usr/bin/ksh egrep -v -e "^\s*#" /file/permission | awk '{ print $1 }' | sort | uniq... (3 Replies)
Discussion started by: gogol_bordello
3 Replies

6. Shell Programming and Scripting

noob question - is awk the tool to clean dirty text files?

Hi, nevermind. I think I've found the answer. It appears I was looking for index, match, sub, and gsub. I want to write a shell script that will clean the html out of a bunch of files and format the data for import into excel. Awk seems like a powerful tool, but it seems oriented to... (1 Reply)
Discussion started by: yogert909
1 Replies

7. Solaris

to clean unnecessary files and folders

I want to clean used solaris OS and then to give another developer. How can I understand that difference between system file/folder and others. I want to delete apart from the files/folders. I need tools or scripts like disk-cleanup or something like that. #usr>du -s -h * 6.6M 4lib ... (1 Reply)
Discussion started by: getrue
1 Replies

8. Shell Programming and Scripting

Script to FTP,clean up and email

Hi i need a unix script to do the following tasks. My folder structure is /home/MSTR/test and will have the following folder within it Cache Lookup Source Target 1. On the Source & Target folder i have to take a copy of files older than 5 days and move(FTP) it into local machines C:\Backup... (1 Reply)
Discussion started by: Codesearcher
1 Replies

9. Shell Programming and Scripting

Clean up UNIX mail box using script

Hi, I would like to clean up by unix mail mail box thru some script command.. I do know how to delete from mail box ... e.g. $ mail ? d* ? quit But I need to clean up thru some command which I can use in my script before sending any email.. Thanks in advance! (1 Reply)
Discussion started by: pareshkp
1 Replies

10. Shell Programming and Scripting

How to clean 3 days before files, from a directory?

I have a Solaris System. I am using bash shell. I want to prepare a script which can do the below. There are few directories i need to clean. In those directories, I need to delete files which are older than 3 days. 3 days before files need to be deleted. The directories are as follows.... (7 Replies)
Discussion started by: Saidul
7 Replies
Date::Manip::TZdata(3)					User Contributed Perl Documentation				    Date::Manip::TZdata(3)

NAME
Date::Manip::TZdata -- Internal module for working with the tzdata files SYNOPSIS
use Date::Manip::TZdata; $tzd = new Date::Manip::TZdata($dir); DESCRIPTION
This module is not intended for public use. It is used internally by the scripts used to analyze the time zone database and generate the modules for each time zone. The module is included in the distribution solely for the sake of completeness. Currently, no support is offered for this module, and it can (and may) change without notice. This module consists of routines for working with the tzdata files obtained from ftp://elsie.nci.nih.gov/pub/ . These files are updated several times a year and are the basis for time zone descriptions for most computer systems. At some point, I am interested in making this module a direct interface to the tzdata files, but in the limited amount of time I have to work on perl modules, other modifications to Date::Manip are much higher priority, so I'm not sure when (or if) this will ever happen. ROUTINES
new use Date::Manip::TZdata; $tzd = new Date::Manip::TZdata($dir); This finds and reads in all the tzdata. If $dir is passed in, it is the directory where a tzdata directory is located. It defaults to the current directory. KNOWN LIMITATIONS
Some assumptions and limitations are assumed in the logic of this module. When a time change occurs, the time may change backwards or forwards. Time changes rules are listed on a per-year basis. It is assumed that time changes will not occur so close to the end or start of the year as to cross the year boundary (in other words, the year will not change as a result of the time change). This is not accounted for, and it is hoped that this situation will never occur. Also, because this module is strictly limited to 4 digit positive years (regardless of whether it is wallclock or universal time), and because various parts of the module switch back and forth, valid times for this module are from Jan 2, 0001 to Dec 30, 9999. This ensures that conversions from wallclock to universal or vice versa will never make dates occur in the year 0000 or 10000. KNOWN BUGS
None known. BUGS AND QUESTIONS
Please refer to the Date::Manip man page for information on submitting bug reports or questions to the author. AUTHOR
Sullivan Beck (sbeck@cpan.org) perl v5.12.1 2010-01-12 Date::Manip::TZdata(3)
All times are GMT -4. The time now is 08:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy