List all old files except 15 latest files

Guys,

Someone please guide me to tell me how do I print and later remove all old files in a folder recursively but keep only latest 15 modified files.

When I do - ls -tp | head -15

I get the list of last 15 modified files whereas I need the list of all OTHER files except these files.

Someone please guide me on this since its fairly urgent.

I wish to use find by something like -

find . \! -newer $`\(ls -tp | head -11 \)` -exec rm {} \;

OR

find . -not -newer $(ls -tp | head -11) -print

Or anything that will make this condition work.

Thanks in advance,
RockF1Bull

One way:

ls -t | awk 'NR > 15'

Thanks Franklin, that was simply awesome and worked straight away!!!

Though I am actually having a bit of a problem here -

While in a certain directory, when I do -

find . $(ls -tp | awk 'NR > 15') -exec rm {} \;

It throws me errors saying, -

find: filename1: No such file or directory
find: filename2: No such file or directory
find: filename3: No such file or directory
find: filename4: No such file or directory
find: filename5: No such file or directory

Please give me a clue if you know how to fix it.

I have tried following though it didn't work.
-

find . $'(ls -tp | awk 'NR > 15')' -exec rm {} \;

Cheers.

Thanks guys, it indeed worked!!!

However, I was wondering if its possible for it to run like a loop in recursive folders.

Below is what I tried to do though it didn't work out and I got "syntax error" message.

Line -

find . $(ls -tp | awk 'NR > 15') -exec rm {} \;
OR
find . ! -newer $(ls -tp | awk 'NR > 15') -exec rm {} \;

If someone can shed more light on this, that will be really great.