Delete 3 oldest files

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 08-09-2018
Delete 3 oldest files

Trying to delete my 3 oldest files.

I am learning despite the many questions.

This shows the files.
Code:
ls -1r /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Documents.zip_* | tail -n+6

adding this on did not work.

Code:
| -exec rm {}

------ Post updated at 05:43 PM ------

This works, but I seek advice from the gurus.
Code:
ls -1r /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Documents.zip_* | tail -n+3 > To_Be_Deleted.txt
xargs rm  < To_Be_Deleted.txt

I can see a problem.

Each time it runs it will delete more files until they are all gone. :-)

------ Post updated at 09:02 PM ------

I think I need to capture the count of files, and then control execution to remove that count.

Last edited by drew77; 08-09-2018 at 08:32 PM..
# 2  
Old 08-10-2018
Think about your requirement.
Maybe it is better to keep a certain number of files?
# 3  
Old 08-10-2018
You are right.
# 4  
Old 08-10-2018
Keeping backups 3 days would be unacceptable in most organization.
# 5  
Old 08-10-2018
Quote:
Originally Posted by Neo
Keeping backups 3 days would be unacceptable in most organization.
Yes.
A lot is depending on being able to restore. :-)
# 6  
Old 08-10-2018
Quote:
Originally Posted by drew77
Yes.
A lot is depending on being able to restore. :-)
What difference does that make?

If a criminal gets into a system or a rouge employee does bad things to data, that is normally not discovered immediately, something it might be not be discovered for many days, weeks or even months.

Three days of backup assumes that you are not concerned about any of those basic IT security topics and you just want to restore from a crash.

That's a very narrow view of the reason for making backups.
# 7  
Old 08-10-2018
I have already told you that I am NOT an admin.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Delete oldest folder based on folder named as date humble_learner Shell Programming and Scripting 3 07-31-2018 10:05 AM
Finding oldest files migurus UNIX for Advanced & Expert Users 3 07-04-2018 03:27 AM
Script needed to delete to the list of files in a directory based on last created & delete them prasadn Shell Programming and Scripting 2 03-02-2015 09:01 AM
Delete all files if another files in the same directory has a matching occurrence of a specific word kridhick Shell Programming and Scripting 7 11-19-2014 06:47 AM
Concatenate files and delete source files. Also have to add a comment. eskay UNIX for Dummies Questions & Answers 0 06-27-2013 07:31 PM
Keeping oldest backup files? Calab Shell Programming and Scripting 3 06-27-2013 12:54 PM
To delete the oldest files in a file when file count in the folder exceeds 7 akshay01987 UNIX for Dummies Questions & Answers 1 10-01-2012 03:32 AM
Moving files only by oldest file one at a time chamajid Shell Programming and Scripting 2 05-21-2012 05:30 PM
Need help creating a script to FTP files to a server and then delete the files that were transfered. jmalfhs Shell Programming and Scripting 4 01-18-2012 10:55 AM
Delete all files if another files in the same directory has a matching occurence of a specific word premier_de Shell Programming and Scripting 2 11-20-2009 05:48 AM
Finding the oldest file janet Shell Programming and Scripting 5 03-23-2009 11:31 AM
delete oldest images from remote server Destined Shell Programming and Scripting 1 08-18-2008 04:49 PM
sort files by date, delete oldest, if total size bigger than scarfake Shell Programming and Scripting 2 05-21-2008 09:02 AM
Oldest files 2dumb Shell Programming and Scripting 2 05-04-2007 04:57 PM
Oldest File In A Directory bergerj3 UNIX for Dummies Questions & Answers 2 02-27-2002 03:31 PM