Hi,
I have a folder/dir which have file names as below.
file1.txt
file2.txt
file3.txt
.
.
Such files are added to the folder daily. I have to keep only latest 10 files in the folder and delete the old files.
I have tried several ways. But couldn't find a better logic.
I have a folder/dir which have file names as below.
file1.txt
file2.txt
file3.txt
.
.
Such files are added to the folder daily. I have to keep only latest 10 files in the folder and delete the old files.
I have tried several ways. But couldn't find a better logic.
Code:
ls -t|tail -n 10;ls|sort|uniq -u|xargs rm
or
rm `ls -t | awk 'NR>10'`