Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
Delete files excluding latest file
Name: raja76 Date: June 24, 2003 at 14:21:02 Pacific OS: Sun OS 5.6 CPU/Ram: Sun OS 5.6
Comment:
Delete files in a certain directory except the latest created file.
for example: payroll_12102003.pdf payroll_10102003.pdf payroll_9102003.pdf payroll_8202003.pdf
Here payroll_12102003.pdf is the latest file created among all files in the directory. Now, I have to delete all files in the directory except payroll_12102003.pdf.
Any one suggest me how to skip the latest file in the directory not to delete and delete remaining files.
Maybe something like the following (take out the "print" to enable actual deletion):
#!/bin/ksh
function delete_all_but_first { shift
for f in $@ do [[ -f $f ]] && print rm $f done }
delete_all_but_first $(ls -C1 -t)
0
Response Number 2
Name: Raja Date: June 30, 2003 at 08:01:45 Pacific
Reply:
Thank you for the reply. It helped me alot. I was trying with awk command and not get through. Could you suggest me any books that helps to learn shell scripts. once again, thanks for the response.
Summary: I have a solaris e250 box where the root partition have becom full. I need to recover space but when I delete files using rm the space they take up is still in use. As you can guess I am very new to S...
Summary: Will u please give me a solution for deleting the files starting with arch* created before 2hrs back. eg: /var/tmp/ contains file like rw-r----- 1 ora1 dba 104851456 Dec 18 11:31 arch1_35303...