Solved

Removing a list of files from a rang of dates

Posted on 2004-09-03
22
288 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
ID: 11973175
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
ID: 11973223
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
ID: 11973280
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
ID: 11973300
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
ID: 11973350
you also can try use -atime parameter instead of -mtime.

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

Author Comment

by:LindaC
ID: 11973378
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
ID: 11973518
atime meaning access time. -atime +1  will return files that  were accessed one day ago.
0
 
LVL 8

Author Comment

by:LindaC
ID: 11973605
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
ID: 11973652
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
ID: 11973669
Also, Solaris v5.9 implemented File Access Control Lists (FACLs). Do the persistent files have an ACL blocking you from deleting them?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Author Comment

by:LindaC
ID: 11973677
Yes, I have permission.
0
 
LVL 19

Expert Comment

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

Author Comment

by:LindaC
ID: 11973721
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
ID: 11973769
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
ID: 11973847
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
ID: 11973858
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
ID: 11975324
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
ID: 11977875
yes. '.' should be replaced by your directory
0
 
LVL 38

Accepted Solution

by:
yuzh earned 50 total points
ID: 11986630
>>>>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
ID: 12357490
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

910 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

24 Experts available now in Live!

Get 1:1 Help Now