Removing the oldest file in a directory

Hi all,

I need your assistance in removing the oldest file in a directory.

I posted the same thread 3 days back and I got the following answer

ls -1 -t | tail -1 | xargs rm

which is not covering the case when there are directories older than the oldest file.

So, could you please provide an option so that the above command will exclude the directories in the search.

Thanks in advance for your help

Pavan

try this

ls -1 -lt | awk ' /^-/ { print $9}' | tail -1 | xargs rm

Thanks a lot anbu23 for your help!!

Regards

Pavan