Solved

Removing a list of files from a rang of dates

Posted on 2004-09-03
22
287 Views
Last Modified: 2013-12-27
I want to remove manualy a list of files that have the date earlier than September 2.  Not including September 2, how can I do it.
Solaris 5.9.
0
Comment
Question by:LindaC
  • 8
  • 8
  • 2
  • +1
22 Comments
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
find /your/dir -mtime +1 -exec rm {} \;

It will remove all files that are modified more that 1 day ago

0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
I executed your script, but there are still files from September 1 there:
What went wrong?

mapdev(oracle)#ls -lt
total 2593282
-rwxrwxrwx   1 oracle   dba          213 Sep  2 15:07 test.sh
-rw-r-----   1 oracle   dba      36882197 Sep  1 16:38 arch_mapdev0000006473.arc
.Z
-rw-r-----   1 oracle   dba      36462688 Sep  1 16:36 arch_mapdev0000006472.arc
.Z
-rw-r-----   1 oracle   dba      36642123 Sep  1 16:35 arch_mapdev0000006471.arc
.Z
-rw-r-----   1 oracle   dba      35212602 Sep  1 16:32 arch_mapdev0000006470.arc
.Z
-rw-r-----   1 oracle   dba      38314167 Sep  1 15:58 arch_mapdev0000006469.arc
.Z
-rw-r-----   1 oracle   dba      38463725 Sep  1 15:55 arch_mapdev0000006468.arc
.Z
-rw-r-----   1 oracle   dba      37801815 Sep  1 15:53 arch_mapdev0000006467.arc
.Z
-rw-r-----   1 oracle   dba      38153479 Sep  1 15:51 arch_mapdev0000006466.arc
.Z
-rw-r-----   1 oracle   dba      37899471 Sep  1 15:49 arch_mapdev0000006465.arc
.Z
-rw-r-----   1 oracle   dba      36393595 Sep  1 15:38 arch_mapdev0000006464.arc
.Z
-rw-r-----   1 oracle   dba      34954212 Sep  1 15:36 arch_mapdev0000006463.arc
.Z
-rw-r-----   1 oracle   dba      37545823 Sep  1 15:35 arch_mapdev0000006462.arc
.Z
-rw-r-----   1 oracle   dba      37551945 Sep  1 15:33 arch_mapdev0000006461.arc
.Z
-rw-r-----   1 oracle   dba      37121976 Sep  1 15:31 arch_mapdev0000006460.arc
.Z
-rw-r-----   1 oracle   dba      36156569 Sep  1 15:29 arch_mapdev0000006459.arc
.Z
-rw-r-----   1 oracle   dba      34651479 Sep  1 15:28 arch_mapdev0000006458.arc
.Z
-rw-r-----   1 oracle   dba      33893293 Sep  1 15:23 arch_mapdev0000006457.arc
.Z
-rw-r-----   1 oracle   dba      39852001 Sep  1 15:05 arch_mapdev0000006456.arc
.Z
-rw-r-----   1 oracle   dba      39812589 Sep  1 15:03 arch_mapdev0000006455.arc
.Z
-rw-r-----   1 oracle   dba      38642300 Sep  1 15:00 arch_mapdev0000006454.arc
.Z
-rw-r-----   1 oracle   dba      39425691 Sep  1 14:58 arch_mapdev0000006453.arc
.Z
-rw-r-----   1 oracle   dba      40122795 Sep  1 14:56 arch_mapdev0000006452.arc
.Z
-rw-r-----   1 oracle   dba      40330079 Sep  1 14:54 arch_mapdev0000006451.arc
.Z
-rw-r-----   1 oracle   dba      40228699 Sep  1 14:52 arch_mapdev0000006450.arc
.Z
-rw-r-----   1 oracle   dba      40713307 Sep  1 14:47 arch_mapdev0000006449.arc
.Z
-rw-r-----   1 oracle   dba      40478345 Sep  1 14:45 arch_mapdev0000006448.arc
.Z
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
mtime parameter returns true if file was modified one day ago.
What is your current time ?
Could you send output of date command ?
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
The output is this:

server name (oracle)#  date
Fri Sep  3 11:02:14 AST 2004
server name (oracle)#
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
you also can try use -atime parameter instead of -mtime.

 find /your/dir -atime +1 -exec rm {} \;
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
What is atime ?

I just want to remove the files (trunc the time please)  from more than one day ago.

Example, today is September 3, then I want to eliminate the files from Septemer 1.
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
atime meaning access time. -atime +1  will return files that  were accessed one day ago.
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
There are still files from September 1 in the directory.  this is the steps that I followed:
If there can be a way of ignoring the time, like truncate the time and then all files that are written on the directory from more than one day ago will be eliminated.


server(oracle)#  pwd
/ORADATA/server/u04/arc
server (oracle)#find /ORADATA/server/u04/arc -atime +1 -exec rm {} \;
server(oracle)#
-rw-r-----   1 oracle   dba      33597333 Sep  2 10:36 arch_mapdb0000004090.arc.
Z
-rw-r-----   1 oracle   dba      22582961 Sep  2 09:15 arch_mapdb0000004089.arc.
Z
-rw-r-----   1 oracle   dba      26427616 Sep  2 09:11 arch_mapdb0000004088.arc.
Z
-rw-r-----   1 oracle   dba      36881715 Sep  2 09:06 arch_mapdb0000004087.arc.
Z
-rw-r-----   1 oracle   dba      38440415 Sep  2 09:02 arch_mapdb0000004086.arc.
Z
-rw-r-----   1 oracle   dba      40674947 Sep  2 08:59 arch_mapdb0000004085.arc.
Z
-rw-r-----   1 oracle   dba      40390429 Sep  2 08:55 arch_mapdb0000004084.arc.
Z
-rw-r-----   1 oracle   dba      41068423 Sep  2 08:52 arch_mapdb0000004083.arc.
Z
-rw-r-----   1 oracle   dba      40943004 Sep  2 08:48 arch_mapdb0000004082.arc.
Z
-rw-r-----   1 oracle   dba      40923801 Sep  2 08:45 arch_mapdb0000004081.arc.
Z
-rw-r-----   1 oracle   dba      41024751 Sep  2 08:41 arch_mapdb0000004080.arc.
--More---rw-r-----   1 oracle   dba      38741243 Sep  1 19:25 arch_mapdb0000004025.arc.
Z
-rw-r-----   1 oracle   dba      38990345 Sep  1 19:16 arch_mapdb0000004024.arc.
Z
-rw-r-----   1 oracle   dba      39377955 Sep  1 19:07 arch_mapdb0000004023.arc.
Z
-rw-r-----   1 oracle   dba      36396799 Sep  1 18:57 arch_mapdb0000004022.arc.
Z
-rw-r-----   1 oracle   dba      35038115 Sep  1 18:19 arch_mapdb0000004021.arc.
Z
-rw-r-----   1 oracle   dba      35488418 Sep  1 17:42 arch_mapdb0000004020.arc.
Z
-rw-r-----   1 oracle   dba      35406975 Sep  1 17:06 arch_mapdb0000004019.arc.
Z
-rw-r-----   1 oracle   dba      30305043 Sep  1 16:29 arch_mapdb0000004018.arc.
Z
-rw-r-----   1 oracle   dba      23757154 Sep  1 16:03 arch_mapdb0000004017.arc.
Z
-rw-r-----   1 oracle   dba      14164813 Sep  1 12:32 arch_mapdb0000004016.arc.
Z
-rw-r-----   1 oracle   dba      17041127 Sep  1 12:16 arch_mapdb0000004015.arc.
Z
-rw-r-----   1 oracle   dba      28539745 Sep  1 12:15 arch_mapdb0000004014.arc.
--More--
0
 
LVL 34

Expert Comment

by:PsiCop
Comment Utility
Do you have write permission to the directory with the user ID under which you are running the script?
0
 
LVL 34

Expert Comment

by:PsiCop
Comment Utility
Also, Solaris v5.9 implemented File Access Control Lists (FACLs). Do the persistent files have an ACL blocking you from deleting them?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Author Comment

by:LindaC
Comment Utility
Yes, I have permission.
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
It seems that those files were updated on 2 September. Could you check it ?
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
The script is functioning but not in the way I wanted.
The script is deleting the files but is taking the time to detect what is +1 day ago.
What I want is to delete the following:  Example:  today is September 3, then I want to delete all the files from Septtember 1.  (ignoring the time)
In Oracle we have like trunc(sysdate) -1.  In Unix I supposed you must have something like that?
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
remove + sign:

 find /your/dir -mtime 1 -exec rm {} \;

+ sign means more that 1 day . But 1 September is exactly 1 day.

0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
So for future your command should be
find . \( -mtime +n -o -mtime n \) -exec  rm {} \;

where n should be replaced by number of days.
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
SQL> select sysdate from dual;

SYSDATE
---------
03-SEP-04

SQL> select trunc(sysdate)-2 from dual;

TRUNC(SYS
---------
01-SEP-04  --------------------------------------------> September 1 is exactly 2 days before from today.  Today is September 3

SQL>
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
ramazanyich:  Should the instruction  find . --> be replaced with my directory  ?
I do not want to erase files that are not mine in other subdirectories.
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
yes. '.' should be replaced by your directory
0
 
LVL 38

Accepted Solution

by:
yuzh earned 50 total points
Comment Utility
>>>>I want to remove manualy a list of files that have the date earlier than September 2.  Not including September 2.

Use " touch + find " to do the job:

touch -t [YY]MMDDhhmm filename

eg:
touch -t 09020000 mystamp

find /path-to/dir -type f  ! -newer mystamp -exec rm {} \;
rm mystamp

man touch
man find
to learn more
0
 
LVL 38

Expert Comment

by:yuzh
Comment Utility
For a given date, coment http:Q_21118175.html#11986630
is the better answer, it still work if you try it today.

Comment http:#11977875 only work, if you run the command on
Sep 4, 2004.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now