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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to suppress file in a directory with 3 millions files !!! 3

Status
Not open for further replies.

yoda37

Technical User
Oct 30, 2006
15
FR
Hi


I'd like to delete files with a date < 2005 in a directory that contains 3 000 000 files.

How to do it without .... out of memory error !!!

Thanks in advance
Den
 
man find



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
you can do something like this:

find ./ -mtime +365 -type f -exec ls -la {} \;

This will list all files (-type f) that are 365 days old or older. Adjust the mtime number as needed so that it starts picking up your old files at the appropriate/approximate date.

You might even want to send that output to a file and review it. If it there are no gotchas, you can change the command to this:

find ./ -mtime +365 -type f -exec rm {} \;

This command will find and delete all files that have not been modified in 365+ days.

As with all "mass" rm commands, use caution. And as already mentioned, "man find" will help you too.

scott
 
to do precisely files last modified before 2005:

Code:
# make a file with mod time 01/01/2005 at the zeroeth minute
touch 0101000005 /tmp/markerfile

#this find is all one line
find /3mil_dir -type -f ! -newer /tmp/markerfile -exec mv {} /dir_with_room \;

# then look through /dir_with_room to make sure you didn't overgrab.
# 
# or you could just make an ls pass to confirm, as scott suggested

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
You'll need that -t option to set the timestamp option with touch.

Ethan
 
The -t option is not needed in the example code.

The -t option takes a different format time string, but does let you specify down to the second, should you need to.

- Rod
 
I see that now in the man page. I must have mistyped the time stamp when testing your command since it had created a file with the name 0101*.

I stand corrected :), I missed a zero.

Ethan
 
Hi Rod

here my game test.

sr1212[root]/tmp/test>ls -lrt
-rw-r--r-- 1 root system 0 Apr 21 2006 a
-rw-r--r-- 1 root system 0 Jun 29 00:01 h
-rw-r--r-- 1 root system 0 Jun 30 00:01 i
-rw-r--r-- 1 root system 0 Jun 30 00:01 b
-rw-r--r-- 1 root system 0 Jul 01 00:01 markerfile
-rw-r--r-- 1 root system 0 Jul 01 00:01 c
-rw-r--r-- 1 root system 0 Jul 02 00:01 d
-rw-r--r-- 1 root system 0 Jul 03 00:01 e
-rw-r--r-- 1 root system 0 Aug 01 00:01 f
-rw-r--r-- 1 root system 0 Aug 15 00:01 g

find ./ -type -f ! -newer ./markerfile -exec ls -la{} \;
=> result nothing !
find ./ -type -f -newer ./markerfile -exec ls -la{} \;
=> result nothing !

Where is my mistake ?

Regards
Den


 
Den,

If you really had "-la{}" with no space before the opening brace, you should have had a bunch of errors. Were you by chance redirecting stderr?

Either insert a space there, or if you already did, delete "-exec ls -al {} \;", then add "-ls".

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
Personally speaking I'd always use find with a specific path, ie:

find /tmp/test <the rest of your find command>

so that you're sure that your searching the correct path.

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
Hi

The mistake was on the -f
the good syntax is

find ./ -type f ! -newer ./markerfile -exec ls -la {} \;

I think that i need to find a good pair of glasses !

Regards
Den

 
Thanks, Den

Adding a dash to the argument after '-type' in a find command is my number one most frequent typo. I guess my subconscious thinks any single letter on a command line must be an option. :)


- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
Hi Rod

errare humanum est !!!
And your first post was a big help ...

Regards
Den
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top