Find latest date in folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find latest date in folder
# 1  
Old 07-22-2013
Find latest date in folder

HI

I have folder in home dir.
Code:
/home/kpp/07222013
/home/kpp/07212013
/home/kpp/07202013

Output :--

Code:
/home/kpp/07222013

Just find latest date
# 2  
Old 07-22-2013
Does the name correspond to the date of last modification?

Would
Code:
ls -t | head -n 1

work ?
# 3  
Old 07-22-2013
NO Base on modification !!!!

I want base on date !!!!

Moderator's Comments:
Mod Comment Please hold the exclamation marks

Last edited by Scrutinizer; 07-22-2013 at 04:16 PM..
# 4  
Old 07-22-2013
if filename = mofication date, try:
Code:
ls -1d /home/kpp/* | awk -F"/" '$0>a[$0]{a[$0]=$0} END {print a[$0]}'

# 5  
Old 07-22-2013
Code:
Try:
ls /home/kpp/* | awk -F/ '{d=substr($NF,5,4) substr($NF,1,4)} d>m{f=$0; m=d} END{print f}'

or
Code:
cd /home/kpp
ls | awk ...

The latter will avoid line length limitations...

Last edited by Scrutinizer; 07-22-2013 at 04:18 PM..
# 6  
Old 07-22-2013
Alternative with sort:

Code:
ls /home/kpp/* | sort -k1.5 -k1.1,1.2 -k1.3,1.4 | tail -n 1

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. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

3. Shell Programming and Scripting

How to find last updated date and time of a folder in Perl?

Hi All, I have a process which after some time continues move a files to some folder(say the name of the folder is logdir) What i am trying to do is as the files are coming to the logdir folder, I want the latest updated time and date of the folder in PERL. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

4. UNIX for Dummies Questions & Answers

Copy the latest (last file) in given folder

#!/bin/bash for i in {1..1536..1} do #find /home/test/Desktop/up111/workplace/Malware/$i/logs for a in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do #max=a for b in /home/test/Desktop/up111/workplace/Malware/$i/logs/* do ... (4 Replies)
Discussion started by: upvan111
4 Replies

5. HP-UX

How can I find the size of files added to a folder after a particular date

Hi, I want to find the size of the files added to a folder after a certain date(say 1st of october), I know we can list the files which were created after a certain date , but is there anyway to find the total size of those files ? (3 Replies)
Discussion started by: alookachaloo
3 Replies

6. Shell Programming and Scripting

Find the latest folder

Hi, I want to find out the files that are created the recent, how can I do it? find . -type d ( i dont know what option to use to find the latest, it can be 1 day old or 10 days, but want to pick the latest one only) Thanks, (5 Replies)
Discussion started by: rudoraj
5 Replies

7. UNIX for Dummies Questions & Answers

how to find folder size with created date

hi, please give me adivse .how to find the folder size with created created date . eg: i have directore and in that sub directoties and so on.. /home/mud/abc/dcb/ for this i want output like this path size date -------------------------------------------... (3 Replies)
Discussion started by: muddasani
3 Replies

8. Shell Programming and Scripting

Copying latest file into a folder

Hello all, this is my first post while i am trying to understand unix. I would basically like to know if i can do this: Lets say i have a folderA and folderB And i save something in folderA Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Discussion started by: takissd
16 Replies

9. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

10. UNIX for Dummies Questions & Answers

Copy the latest file from a folder

Hi, I have a problem. I have some text files in a folder. The names can be like: emp_20080307053015.dat emp_20080306053015.dat emp_20080305053015.dat emp_20080304053015.dat The date format appended is like yyyymmdd and timestamp. What i need is i have to copy the latest file every... (3 Replies)
Discussion started by: Aswarth
3 Replies
Login or Register to Ask a Question