Delete 3 oldest files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete 3 oldest files
# 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. UNIX for Advanced & Expert Users

Finding oldest files

There are some 25,000 files in 7,000 directories in my source library and I am trying to find oldest files. I am running this find: find /usr/mysrc -name "*." -type f -mtime +8000 -exec ls -l {} 2>/dev/null and playing with the days parameter for mtime, but the output is not sorted... (3 Replies)
Discussion started by: migurus
3 Replies

3. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

4. Shell Programming and Scripting

Keeping oldest backup files?

I need a script to clean up the files on our backup system. I was hoping this would be simple for someone to put together for me. I'm sure I could do it, but I'm a bash n00b so it would definitely not be efficiently or within a reasonable amount of time. :( Requirements: - Root of backups... (3 Replies)
Discussion started by: Calab
3 Replies

5. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

6. Shell Programming and Scripting

Moving files only by oldest file one at a time

Hi I am want to create a script where the file gets moved from the current folder to a folder transfer based on the oldest first. This script should run one file at a time using a loop. I want it as a loop because I want to do some processing while I have one file. Can anyone guide me on this? (2 Replies)
Discussion started by: chamajid
2 Replies

7. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

8. Shell Programming and Scripting

delete oldest images from remote server

Would someone please give me a script that will remove all but the newest jpg image from my server. i am uploading a new image every 10 seconds form a live web cam Also i do not know who to make a shell script work i am new to all this so i need all the help you could give Thank You very much (1 Reply)
Discussion started by: Destined
1 Replies

9. Shell Programming and Scripting

sort files by date, delete oldest, if total size bigger than

hello people i need your help please i want to achieve the following with the simplest, most efficient shell-tools: i have a directory with a lot of files from users. the script should check which partition the dir is on if the partition with the directory is more than 90% full ... (2 Replies)
Discussion started by: scarfake
2 Replies

10. Shell Programming and Scripting

Oldest files

Anyone know of a way to list all of the files including subdirectories and list them as oldest first? (2 Replies)
Discussion started by: 2dumb
2 Replies
Login or Register to Ask a Question