👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Delete 3 oldest files

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 6 Days Ago
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; 6 Days Ago at 07:32 PM..
# 2  
Old 6 Days Ago
Think about your requirement.
Maybe it is better to keep a certain number of files?
# 3  
Old 6 Days Ago
You are right.
# 4  
Old 6 Days Ago
Keeping backups 3 days would be unacceptable in most organization.
# 5  
Old 6 Days Ago
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 6 Days Ago
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 6 Days Ago
I have already told you that I am NOT an admin.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete oldest folder based on folder named as date humble_learner Shell Programming and Scripting 3 2 Weeks Ago 09:05 AM
Finding oldest files migurus UNIX for Advanced & Expert Users 3 07-04-2018 02: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 08: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 05:47 AM
Keeping oldest backup files? Calab Shell Programming and Scripting 3 06-27-2013 11:54 AM
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 02:32 AM
Moving files only by oldest file one at a time chamajid Shell Programming and Scripting 2 05-21-2012 04:30 PM
delete oldest images from remote server Destined Shell Programming and Scripting 1 08-18-2008 03:49 PM
sort files by date, delete oldest, if total size bigger than scarfake Shell Programming and Scripting 2 05-21-2008 08:02 AM
Oldest files 2dumb Shell Programming and Scripting 2 05-04-2007 03:57 PM


All times are GMT -4. The time now is 09:59 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password