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.
CC1,CC2,Int.
The file format inside are(there are many files in the CC1 and CC2 directories)
tmp/test/CC1(dir)-A20140107.2355-0000_jak_file(there are files for every 5 min interval in this format)
A20140107.2355-0000_jak_test(there are files for every 5 min interval in this format)
/tmp/test/CC2(dir)-A20140107.2355-0000_jak_file(there are files for every 5 min interval in this format)
A20140107.2355-0000_jak_test(there are files for every 5 min interval in this format)
It works!
You'll get errors if there are sub-directories. These can be suppressed by -type f or ! -type d.
Further, Unix find offers + instead of \; for -exec; if the command supports multiple arguments (rm does) then + is faster.
Then, rm -f suppresses eventual questions when deleting write-protected files.
This User Gave Thanks to MadeInGermany For This Post:
Thanks for your reply and it did help. I need to do a little modification if you can help me here too.
Actually whatever files i will be deleting from the above mentioned directories I need to do a provision of logging.
How do i achieve the below.?
1. Which dates files have been removed and when?
Simply, provision of logging.
Last edited by Franklin52; 01-29-2014 at 04:48 AM..
Reason: Please use code tags
Thanks for your reply and it did help. I need to do a little modification if you can help me here too.
Actually whatever files i will be deleting from the above mentioned directories I need to do a provision of logging.
How do i achieve the below.?
1. Which dates files have been removed and when?
Simply, provision of logging.
First, note that putting these three commands on one line with no command separator will NOT do what you want.
Second, you don't need to invoke find three times to do this (unless you run into ARG_MAX limitations).
If the rm utility on your system supports the -v option, try:
otherwise, try something like:
Last edited by Don Cragun; 01-29-2014 at 05:17 AM..
Reason: Remove extraneous space in middle of log file name.
This User Gave Thanks to Don Cragun For This Post:
Hi,
I am trying to run a command that finds all files over x amount of days, issue is one of the directories has spaces within it.
find /files/target directory/*/* -type f -mtime +60 When running the above the usual error message is thrown back
+ find '/files/target\' 'directory/*/*' -type... (1 Reply)
Hello,
I need to move all the files inside /XYZ (has multi-depth sub directories) that are older than 14 days to/ABC directory but with retaining the SAME directory structure.
for example:
/XYZ/1/2/3/A/b.txt should be moved as /ABC/1/2/3/A/b.txt
I know about find /XYZ -type f -mtime +14... (3 Replies)
how do i remove sub directories of a directory and all files which are older than 7 days by a single command in AIX. pls help me.
I am using command as
#find /gpfs1/home/vinod/hpc/ -depth -type d -mtime +7 -exec rm -rf {} \;
so i want to delete all sub directories and all files from the... (1 Reply)
Hi All
I want to remove the files with name like data*.csv from the directory older than 10 days.
If there is no files exists to remove older than 10 days, It should not do anything.
Thanks
Jo (9 Replies)
Hi All,
Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below,
1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
May be a simple question for experts here....
I need to get the list of files older than 30 days in the current folder. I tried "find", but it searches recursively in all the sub directories.
Can I restrict the recursive search and extract the files only from current directory ? (18 Replies)
Hello;
I have a directory that is collecting log and act files. I need to write a script that will remove these files once they are 30 days old. I have read through a number of threads on this site that have given me a great deal of information. However I have what seems to be a unique... (7 Replies)