Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files from 2000 and eariler 2

Status
Not open for further replies.

unmlobo

MIS
Apr 11, 2003
64
US
Is there a way to search through a users dir and delete anything that is from the year 2000 and older with one command. I can remove each file individualy but there are over 600 files that they have.Thanks for he help!
 
Use the 'touch' command to create a file with a timestamp of the oldest file you want to keep.

Use the 'find' command to find all files older than the reference file you created in step 1. The find command can also execute commands (eg. rm) on all the files which it finds.

--
 
Try something like this:
touch -t 200012312359 /tmp/stamp.$$
find /path/to/dir -type f ! -newer /tmp/stamp.$$ | xargs rm

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV, won't this remove files that are newer then the year 2000? I need to remove all the files that are form the year 2000 and older.
 
Read carefully the man page for find and pay attention to the [highlight]![/highlight] negation operator.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV, Here is what I did.

touch -t 200012312359 /tmp/stamp.$$

then I did

find /home/user -type f ! -newer /tmp/stamp.$$ > /tmp/rmfile

so I could see want files were going to be deleted. All the files that are sent to rmfile are files newer then 2000. As I am a novice to UNIX...I'm I just not getting it? I did put a space between the F and the ! and the -newer.
 
Which flavor of *nix ?
Worked for me on SCO OSR 5.0.x
Can post the output of [tt]ls -l /tmp/stamp.*[/tt] ?
 
I'm running Solaris 8.

output of ls -l

-rw-rw-rw- 1 users group 0 Dec 31 2000 stamp.5254

The file is cteated ok as far as I can see. It has the right date to it.
 
Sorry, don't understand why it's not working for you.
Seems like the solaris find command checks the inode change time instead of modification time (?).
 
Perhaps ! is magic in some way for your shell

Try
[tt]find /home/user -type f \! -newer /tmp/stamp.$$ > /tmp/rmfile[/tt]

--
 
Thank you both for your help!!!! I'm going to play around with the differnt commands to see what works. I'll post the command that work. Again thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top