|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Deleting files based on CreationTime
In a directory there are files which are generated daily. Format of files, if its generated on 16th Apr 2012 is TEST_20120416.txt. So I need to delete all the files which are older than 7 days. I tried doing this Code:
#!/bin/ksh
find /data/Test/*.* -mtime +7 -exec rm -rf {} \;
exit 0Now the problem is above code is deleting based on modification time but according to requirement file should delete based on creation time.Kindly help me out in deleting files based on filename(filename has timestamp). Last edited by manushi88; 04-16-2012 at 08:10 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
That will be a problem as most unixes don't store the file creation time, and it's not specified in POSIX either. Use Code:
stat <FILE> and check the Birth row to see if your unix supports it. If so, use Code:
find -newerBt <REFERENCE_TIME_STAMP> -exec ... there's no -Btime in most finds, and the +/-N days syntax doesn't work with -newerXY. Last edited by hroptatyr; 04-16-2012 at 04:10 AM.. Reason: provide find-based solution |
| The Following User Says Thank You to hroptatyr For This Useful Post: | ||
manushi88 (04-16-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi,
Unix doesnt support birth row. |
|
#4
|
|||
|
|||
|
Yes, that's exactly what I'm saying. POSIX enforces ctime, mtime and atime, but birth time is not mentioned anywhere. Some versions of the stat(1) command will give you this row though, and many versions of find can deal with it too, but if the birth time cannot be obtained all checks will always fail.
AFAIK, the only unix that does support birth time is FreeBSD. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Please post what Operating System and version you are running. Quote:
Also surely you mean +7 (older) not -7 (newer) ! Try experimenting with command structure like this to see what might be deleted: Code:
#!/bin/ksh
find /data/Test -type f -name 'TEST_*' -mtime +7 -print | while read filename
do
# Remove echo when tested
echo rm -f "${filename}"
doneLast edited by methyl; 04-16-2012 at 05:49 AM.. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
btrfs, zfs, ext4 and hfs+ also store file creation time.
|
| The Following User Says Thank You to jlliagre For This Useful Post: | ||
jim mcnamara (04-16-2012) | ||
| Sponsored Links | ||
|
![]() |
| Tags |
| linux, unix, unix commands |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting files based on the suffix | saggiboy10 | UNIX for Dummies Questions & Answers | 1 | 09-10-2011 08:03 AM |
| Deleting files based on their size | Xterra | Shell Programming and Scripting | 4 | 06-25-2010 02:15 AM |
| Deleting the files based on the date's | kandi.reddy | Shell Programming and Scripting | 1 | 02-17-2010 07:10 AM |
| deleting lines from a delimited files based on a 2nd file | goldie363 | UNIX for Dummies Questions & Answers | 4 | 03-30-2009 02:10 PM |
| command for deleting log files based on some condition | pulkit | Shell Programming and Scripting | 4 | 01-09-2008 05:17 AM |
|
|