Sponsored Content
Top Forums Shell Programming and Scripting Shellscript command to remove files starting with a certain string, and older than 3 days Post 302969936 by jim mcnamara on Wednesday 30th of March 2016 10:24:21 AM
Old 03-30-2016
Quote:
older than 3 days.
The timestamp on a file is the number of seconds since Jan 1 1970. It gets turned into human readable dates using rules in your locale. So, simply subtracting three days from right now may not be what you want - calendar days, not 86400 seconds * 3. One day is 86400 seconds.

Try this: where I am it is Mar 30, 2016
so second "0" of Mar 29 is the cutoff

Code:
cd /path/to/files
touch -t 201603290000 dummy

Two options:
1. just the current directory
Code:
for f in prefix*
do
     if  [ "$f" -ot dummy ] ; then
       rm $f
     fi
done

2. whole directory tree starting from current directory

Code:
find . -type -name 'prefix*'  ! -newer dummy -exec rm {} \;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies

2. Shell Programming and Scripting

Need to remove files older than 30 days except directories

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)
Discussion started by: malaymaru
6 Replies

3. Shell Programming and Scripting

How to tar, compress and remove files older than two days

Hi, I'm Eddy from Belgium and I've the following problem. I try to write a ksh script in AIX to tar, compress and remove the original *.wav files from the directory belgacom_sf_messages older than two days with the following commands. The problem is that I do not find a good combination... (4 Replies)
Discussion started by: edr
4 Replies

4. Shell Programming and Scripting

script to remove files older than 60 days

Hi I need help in the script which looks at a contorl file which has a list of file names like xxxx.12345 and I want to take only xxxxx and search in a specific directory and remove the file if its older than 60 days I have written something like this.. but seems to be wrong... (1 Reply)
Discussion started by: antointoronto
1 Replies

5. Shell Programming and Scripting

remove newline between two string with sed command in unix shellscript

I have a file (test.dat) which contains data like this 459|199811047|a |b |shan kar|ooty| 460|199811047|a |bv |gur u|cbe| but I need it like: 459|199811047|a |b |shankar|ooty| 460|199811047|a |b |guru|cbe| While reading the data from this file, I don't want to remove newline from the end of... (4 Replies)
Discussion started by: jcrshankar
4 Replies

6. UNIX for Advanced & Expert Users

How to Remove 180 days older non-empty directories

Hi Gurus, I have command to delete more than 180days file. find /home/abc/ -name "CBST_*.txt*" -mtime +180 | xargs -n 100 rm -f Now I would like to delete more than 180days Non empty directory--What will be command? Following is non empty directory as instance CBST2010* (2 Replies)
Discussion started by: thepurple
2 Replies

7. Shell Programming and Scripting

[Solved] Remove file older than 90 days

I have crontab job a tar file to a directory ( tar -cvf /tmp/backup/or.`date +%m%d%y`. /ora/db/* ) , it will do it every day . Now I don't want to keep too much files , I just want to keep the file for 90 days , can advise if I want to remove the backup file which are elder than 90 days , can... (1 Reply)
Discussion started by: ust3
1 Replies

8. Shell Programming and Scripting

Find command to search and delete files older than 1 days at a desired location

Hello All, Can someone please help me out in creating the find command to search and delete files older than 1 days at a desired location. Thanks in advance for your help. (3 Replies)
Discussion started by: Pandee
3 Replies

9. Shell Programming and Scripting

Remove files older than 2 days.

Hi All, I am new to the scripting and using solaris 10 OS. Please suggest me from the below script which modifications need to be done to delete the files more that 2days older. Current script is deleting existing file. # Remove old explorer runs if needed DIR=`dirname ${EXP_TARGET}` if ... (2 Replies)
Discussion started by: Navkreddy
2 Replies

10. Shell Programming and Scripting

Remove lines older than 30 days

Hi Experts/Gurus, Is there a way to remove lines in a file that are older than x days (i.e. 30 days) based on the date stamp in the first column? Example. $ date Sat Jan 11 14:12:06 EDT 2014 $cat sample.txt 10-10-2013 09:00:01 AM|Line test 1234567 16-10-2013 08:30:00 AM|Line test... (6 Replies)
Discussion started by: brichigo
6 Replies
PX_INSERT_RECORD(3)													       PX_INSERT_RECORD(3)

px_insert_record - Inserts record into paradox database

SYNOPSIS
int px_insert_record (resource $pxdoc, array $data) DESCRIPTION
Inserts a new record into the database. The record is not necessarily inserted at the end of the database, but may be inserted at any position depending on where the first free slot is found. The record data is passed as an array of field values. The elements in the array must correspond to the fields in the database. If the array has less elements than fields in the database, the remaining fields will be set to null. Most field values can be passed as its equivalent php type e.g. a long value is used for fields of type PX_FIELD_LONG, PX_FIELD_SHORT and PX_FIELD_AUTOINC, a double values is used for fields of type PX_FIELD_CURRENCY and PX_FIELD_NUMBER. Field values for blob and alpha fields are passed as strings. Fields of type PX_FIELD_TIME and PX_FIELD_DATE both require a long value. In the first case this is the number of milliseconds since mid- night. In the second case this is the number of days since 1.1.0000. Below there are two examples to convert the current date or timestamp into a value suitable for one of paradox's date/time fields. Note This function is only available if pxlib >= 0.6.0 is used. PARAMETERS
o $pxdoc - Resource identifier of the paradox database as returned by px_new(3). o $data - Associated or indexed array containing the field values as e.g. returned by px_retrieve_record(3). RETURN VALUES
Returns FALSE on failure or the record number in case of success. EXAMPLES
Example #1 Set the date/time fields in a paradox database to the current date/time <?php $px = px_new(); $fp = fopen("test.db", "w+"); px_create_fp($px, $fp, array(array("timestamp", "@"), array("time", "T"), array("date", "D"))); $curdate = getdate(); $jd = gregoriantojd($curdate["mon"], $curdate["mday"], $curdate["year"]); $days = $jd - 1721425; /* Number of days between 1.1.4714 b.c. and 1.1.0000 */ $secs = $curdate["hours"]*3600 + $curdate["minutes"]*60 + $curdate["seconds"]; px_insert_record($px, array($days*86400000.0 + $secs*1000.0, $secs*1000.0, $days)); $curtimestamp = microtime(true); $days = (int) ($curtimestamp/86400); $secs = $curtimestamp - ($days * 86400.0); $days += 2440588; /* Number of days between 1.1.4714 b.c. and 1.1.1970 */ $days -= 1721425; /* Number of days between 1.1.4714 b.c. and 1.1.0000 */ px_insert_record($px, array($days*86400000.0 + $secs*1000.0, $secs*1000.0, $days)); for($i=0; $i<2; $i++) { $rec = px_retrieve_record($px, $i); echo px_timestamp2string($px, $rec["timestamp"], "n/d/Y H:i:s")." "; echo px_date2string($px, $rec["date"], "n/d/Y")." "; } px_close($px); px_delete($px); ?> The above example will output: 2/21/2006 21:42:30 2/21/2006 2/21/2006 20:42:30 2/21/2006 The Julian day count as passed to jdtogregorian(3) has a different base of 1.1.4714 b.c. and must therefore be calculated by adding 1721425 to the day count used in the paradox file. Turning the day count into a timestamp is easily done by multiplying with 86400000.0 to obtain milli seconds. SEE ALSO
px_update_record(3) PHP Documentation Group PX_INSERT_RECORD(3)
All times are GMT -4. The time now is 01:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy