We use Solaris 10 x86 and I want to use a cron job to remove directories +90 old. Currently I have the command below but it only cleans the files and keeps the directory. What am I doing wrong?
/opt/tesk/batch/kit/archive/* -mtime +90 -exec rm -r {} \:
There are several issues here. The script design is dangerous and probably needs a re-think.
1) It is quite normal to have a parent directory with a modification time older than the directories and files under that directory. Issuing "rm -r" on a directory based on directory timestamps could delete much much more than you expect.
See the timestamp on your root directory for example:
2) Directory cleaning is best done from the bottom of the tree up.
Deleting files and directories updates the parent directory timestamp.
Depending on your requirement you may need a script to identify directories containing only old files and save a list of those directories. The "-depth" parameter to "find" will search directories from the bottom up. Then process each directory in the list in turn, deciding whether to delete the files, and then if the directory is totally empty whether to delete the directory with "rmdir".
3) Always test such scripts without issuing the delete commands until you are happy that you only delete what you want to delete.
Reply to amitranjansahu. The "find" with "-type d" was my first reaction too until I realised that issuing "rm -r" on an old parent directory could delete newer subdirectories.
How to list the directories that are not acessed for more than 500 days?
i used find in the following way
find . -type d -atime +500 -exec du -sh {} \;
but it is listing all the sub direcories of the parent directories which satisfy above condiion.I would like to get just name of the... (1 Reply)
Hi.. i have written a shell script and made this script to run on every day night 11: 55 pm using a cron job.
This cron job running for some days and is not running for some day. but i need this script to run every day night. Please help me.
Here is the cron tab entries,
55 23 * * *... (1 Reply)
Hello
I have some directories and files created under /export/local/user
I would like to delete directories only under /export/local/user, created before 3 days
Can someone help me with command to do this task?
Thanks (4 Replies)
Hello,
Motive: Search all directories which are older than 5 days.
Example: consider following directory structure:
abc/dir1 abc/dir1/dir abc/dir2 abc/dir3 abc/dir3/temp
Suppose dir1 and dir3 are 5 days older. Then I am looking for a command which lists abc/dir1 and abic/dir3 only so that... (4 Replies)
Hello all,
Here's the deal...I have one directory with many subdirs and files.
What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file.
A script for... (5 Replies)
Hi,
I have dummies questions:
My script here can find the files in any directories older than 30 days then it will delete the files but not the directories. I would like to also be able to delete the directories that hold old files more than 30 days not just the files itself.
find . -type f... (2 Replies)
Can any one please help me in deleting all the Files over 7 days from sub-directories A, B, C...
Top-Directory
Sub-Directory-A
File-1
File-2
.....
File-n
Sub-Directory-B
File-1
File-2
.....
File-n
Sub-Directory-C
File-1
... (1 Reply)
Hi,
My requirement is need to delete the directories (Including files also) which are older than 7 days. So I used below command in one script (script takes 2 input parameters)
#$1 - Path of the directory from where we have to delete the directories.#
#$2 - Number of days older... (1 Reply)
Hi,
I need to remove files (*.trc) which are older than 30 days from one location.
My problem is there I do not want to visit any of the directories at that location. I want to search files at that particular location only (need to skip directorys at that location). maxdepth option is there... (6 Replies)