Delete all Files except the Latest Files

Hi,
In my scenario, i just want to delete all the files except the latest one.
How can I do?
Please reply me.

Several possibilities.

'find -mtime' or 'find -ctime' will find old files - but it only has ~ one day resolution.
See man find.

Or cou could do a 'ls -lrt' which will list files sorted by date in reverse (-r) order. Combine it with head, tail, awk, xargs, rm to get your desired result.

If it's about log files you could also have a look at the logrotate package, which gives you lots of possibilities of rotating, deleting, compressing files in an automated fashion.

Hope this helps,
n.

you can use -amin instead of atime or mtime ( its not supported in some OS).

or find -newer

see the man page of find.

Try:

ls -1t |awk 'NR>=2 { print $ 0; }' | xargs rm