Finding oldest files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Finding oldest files
# 1  
Old 07-03-2018
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:
Code:
  
 find /usr/mysrc -name "*.[ch]" -type f -mtime +8000 -exec ls -l {} 2>/dev/null

and playing with the days parameter for mtime, but the output is not sorted and it took me a while to guess the 8000.

I wander if there is an easy way to do that.
# 2  
Old 07-03-2018
It always pays off to be as specific as possible ("how many oldest files do you need?") and to post OS and find versions so you dont't get advice that doesn't work on your system. Try
Code:
find /usr/mysrc -printf "%T@ %p\n" | sort | less

if your find provides the printf action.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-03-2018
Not quite correct (*), but might work in practice
Code:
find /usr/mysrc -name "*.[ch]" -type f -mtime +365 -exec ls -lt {} +

(*) If the argument list (that is collected by the +) becomes too long for the ls, then ls is called another time with the remaining arguments, and the -t sorting becomes wrong.
Therefore the -mtime +365 is an attempt to reduce the argument list.
# 4  
Old 07-04-2018
Quote:
Originally Posted by RudiC
Code:
find /usr/mysrc -printf "%T@ %p\n" | sort | less

if your find provides the printf action.
I liked the idea of using the seconds since epoch. This is old SCO system, its find does not have printf option. Found a gnutools with find that supports printf option and located all the files I wanted to review. Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete 3 oldest files

Trying to delete my 3 oldest files. I am learning despite the many questions. This shows the files. ls -1r /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/Ubuntu_Documents.zip_* | tail -n+6adding this on did not work. | -exec rm {}------ Post updated at 05:43 PM ------ This works, but I... (15 Replies)
Discussion started by: drew77
15 Replies

2. 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

3. 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

4. UNIX and Linux Applications

Finding the oldest file in a directory without ls

I am trying to determine the oldest and most recent files in a huge directory. I am using an ls -tr statement outside my find statement. The directory is too big and I am getting an "arg list too long" error. Is there something I can put in my find statement that doesn't create a list to... (2 Replies)
Discussion started by: hiyofjord
2 Replies

5. Shell Programming and Scripting

Finding the oldest file in a particular directory

Hi all, I am a newbie to scripting and I need your help regarding finding the oldest file in a particular directory. My intention is to remove that oldest file. Are there any options available with the "find" command to do this.. Thanks in advance for your help Pavan (4 Replies)
Discussion started by: pavan_movva
4 Replies

6. Shell Programming and Scripting

Finding the oldest file

Hi:- I need help with a script I need to modify: - what's the best/easiest way to find out the oldest file in a directory and then move this file to another directory? Thanks, (5 Replies)
Discussion started by: janet
5 Replies

7. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

8. 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

9. 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

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question