Linux / UNIX Tech Support Forum
This is a discussion on How to Delete a file on 46 th day from the day of creation within the Shell scripting forums, part of the Development/Scripting category; hi I am expecting a script that delete the files from a directory. The file should be deleted on 46th ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi
I am expecting a script that delete the files from a directory. The file should be deleted on 46th day from the date of creation. It's better if you use "crontab -e" Input: file1,file2,file3 created on Dec23 say. These files should be deleted on feb10 approxmately. Note that my script should run everyday at Midnight12:05 and check the files in a directory specified. Any help is really appreciated. Its really urgent.....Plz Thanks, Pavan. |
| Sponsored Links | ||
|
|
|
||||
|
You can't as Linux / UNIX do not store date of creation for any file.
__________________
Vivek Gite Linux Evangelist |
|
||||
|
However, you can find a file last access tim,e using find command. Like display list of files 46 days old using find command. From the man page:
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago. Code:
find /path/to/dir -atime +45 "*.txt" -print
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Usually what I would do is create a script like so:
#!/bin/sh # # This will remove all files older than 46 days find /path/to/files/ -mtime +46 -exec rm {} \; # Done |
![]() |
| Tags |
| find , finding file , linux , unix |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script to search specific file from txt file inside zip file and extract it | aasif.shaikh | Shell scripting | 2 | 31-05-2008 06:44 PM |
| Shell Script to Automatically Delete a File via Cron Job | kakarla | Shell scripting | 2 | 29-01-2008 08:54 AM |
| how to delete 0 bytes file | puppen | Linux software | 2 | 15-05-2007 09:45 PM |
| Shell script to delete a file with a dialog utility | shankar100 | Shell scripting | 4 | 02-03-2007 10:22 AM |
| mysql account creation | Linux software | 1 | 28-01-2006 11:17 AM | |