Hi All
I require to generate a script that deletes folders and sub directoires from a set period after creation.
So have folder X on a daily basis i have job folders being created folder name 1234568. What i need to do is keep this folder pruned. So say 7 days after creation of the job folder its deleted
thanks
treds
Except for some special cases UNIX does not use create dates - that is purely windows.
the find command uses -ctime (for last time the file metadata changed; usually when it was created) or -mtime (last time the file was written). Pick one.
here is an mtime example
Any directory older than 7 days get clobbered. use either ctime or mtime.
Beware of the red part, you can run it in test mode by exclusing the red code to see what it will do. Why? You can't undelete files in UNIX. rm -r deletes the directory and all of the files and subdirectories under it.
Last edited by jim mcnamara; 12-19-2011 at 11:22 AM..
Reason: can't type
Be very very careful. It is quite normal in unix for a directory to have the value of "-mtime" much much older than the "-mtime" of the subdirectories.
To illustrate this, have a look at some of these timestamps:
Also bear in mind that the action of removing a directory changes the timestamp of the parent directory.
This sort of cleanup needs very careful planning and design.
I don't believe that the script proposed by Jim is at all safe.
Lateral thought idea:
At the time of creating each directory involved in this process, create a timestamp file in the directory. Then use "find" with the "-newer filename" switch to make decisions about that particular directory. This will also ensure that you only look at directories you want to maintain and be prepared to not delete a directory if the subdirectories are not old enough.
Test with "echo" not "rm -r" !!
Hi
still have no luck with this if i run the command
I get the list of files to delete
but if i run the delete
I get the following error on all folders
Any help appreciated
Though I do not endorse the script or the method at all, the error comes from not using the "-depth" switch to "find". Directories and contents and subdirectories and contents have been deleted while they were still in the "find" unprocessed list. Using "rm -r" in directory cleanups is very very dangerous.
Hi All,
I am new in scripting and working in a project where we have RSyslog servers over CentOS v7 and more than 200 network devices are sending logs to each RSyslog servers. For each network devices individual folders create on the name of the each network devices IP addresses.The main... (7 Replies)
My unix version is IBM AIX Version 6.1
I tried google my requirement and found the below answer,
find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20"
But newer command is not working in AIX version 6.1 unix
I have given my requirement below:
Input:
atr files:
... (1 Reply)
Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Hi All,
I need to create links between two directories.
have multiple files in a specified location.
Source Location ex: /opt/xdm/input/
Target Location ex: /opt/xdm
input file names: 1. abc_app.aus.apac.yyyymmdd.dtd
2. abcd_app.aus.apac.yyyymmdd.dtd
I need to build a code that reads... (1 Reply)
Hi,
I have some folders (containing files) which gets created daily and names start with 'TT_' . I would like to remove these folders every month end.
Could you please provide me the commands and also the syntax to schedule through crontab.
Thanks,
Archana (3 Replies)
Hi
I am trying to modify a script that will remove files and folders under a set directory on my server.
I am using the following
find /home/test/HM/ -type d -exec rm -rf {} \; 2>/dev/null
This removes the files in the HM folder but it also removes the HM folder which i do not want to... (3 Replies)
Hello,
I have "mastered" the counting of occurrences with uniq -c. :D
Now I need to keep that file neat and nice and remove only the occurrence number and the space after it.
Example:
1286456 aaa
164758 aab aaa
112345 aac aaf
should be turned into:
aaa
aab aaa
aac aaf
I... (6 Replies)
When I try to remove the file which was created by another user through super user, I am getting the "override protection 644 " meesage.
Could you please anyone help me how will I delete the file without prmpting the override protection.
I have also given the permission (rwx) to the group as... (3 Replies)
Hi All,
Could you please let me know if there is any one can help to create a shell script to remove some files which is the created date for them greate than 10 days (sysdate-10)
Please try to email me on email removed
Thanks in advance,
Murad (1 Reply)
Hello people,
I want to list the files & folders created/modified since a particular date say June 2006. I know I can list recursively thru the folders and use awk to extract the date column to get the desired output.
Just wanted to check whether there is an easier way to do this. Please... (2 Replies)