Help with sorting files according to modification date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help with sorting files according to modification date
# 1  
Old 01-18-2010
Help with sorting files according to modification date

Hi,

I was very surprised to not be able to find an answer to this question despite my best efforts in Google and elsewhere. Maybe it's a good thing as it forced me to finally become a member in this great forum that i use frequently.

Ok my question:

I want to be able to sort files inside a directory (that *may* of course contain sub-directories) according to the *latest modification date*.

e.g. after execution the command/script, I should have a list:

./myrootdir/dir2/subdir1/testing/file_hello.php 22M Jan 15 17:32
./myrootdir/testingteo.txt 12K Jan 03 12:22
./myrootdir/utilities/myscript.ksh 750M Jan 01 11:15
...
... etc.

Maybe I didn't check properly but I couldn't find it! A simple ls -lrt will give me only local files inside the current directory.
I think this would be a very useful tool to check which files were lately modified and/or added inside nested directories.

Need:
My (web shared) server was recently hacked and I wanted a "fast" way to check what files were modified/added.
Would it be difficult to add the same result but for specific file types? e.g. php, cgi, ksh only.

Thanks in advance!
-S
# 2  
Old 01-18-2010
Which OS are you on? I'm assuming Linux here, as you said it's a shared hoster:
Code:
find . -type f -name '*.php' -exec ls -ltr {} \+

Otherwise:
Code:
find . -type f -name '*.php' -print | xargs ls -ltr

Beware, though, that in the case of a lot of files found the list might not be 100% correct, as ls can only sort the files found on the command line, which might be fewer than there are really.

A little hint for the next time: keep a current list of cryptographic checksums (at least MD5 and SHA1, maybe more) offsite, so you can quickly compare any changed/removed/added files.
# 3  
Old 01-18-2010
thanks,

Ok, then if a simple find+xargs can't guarantee that will do the trick depending on the number of files what will?

Also, if you have a link to look into the cryptographic stuff, I would appreciate it.

thanks again!
S
# 4  
Old 01-18-2010
Again, assuming that you run some kind of current Linux (as you haven't told us the OS yet):
Code:
find . -type f -name '*.php' -print | while read file; do stat -c '%y %n' $file; done | sort -n

should give you what you need. However, this depends largely upon the stat utility shipped with Linux (meaning GNU stat), it most probably won't work with that of another OS.

As for the checksums: most Linux distributions and *BSDs (dunno about Solaris) ship with at least md5sum, usually sha1sum and sha256sum too. Those can be used to create and verify cryptographic checksums for a/a lot of file(s).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

2. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

3. Shell Programming and Scripting

Finding files and sorting by date (find | awk)

I am wanting to search a directory tree and return files that are older than a specified datetime. So far straight forward with find, now I want to sort in date order and format the output. So far I have this, but is not working and there is a problem with "." in the file and/or path names. ... (2 Replies)
Discussion started by: larry2311
2 Replies

4. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies

5. Shell Programming and Scripting

Rename old files with last modification date

Hi everyone, I have files like file1_Mod.txt, file2_Mod.txt. I want to rename the old files with the last modification date. I write the below script to rename with current date, but I donīt know how to use "date -r" to get the last modification date with the same format I have below... (5 Replies)
Discussion started by: cgkmal
5 Replies

6. UNIX for Dummies Questions & Answers

Last modification date without 'ls'

Hi, I'm executing a script to check if a file has been modified on a shared folder. I use this to start another script every time the file has been modified. To do this I use the 'ls' command to get the last modification date of the file. My problem is that the computer hosting the shared... (5 Replies)
Discussion started by: Peuj
5 Replies

7. Shell Programming and Scripting

List the file or files with last modification date

hi. I need help my programing friends :p I need to list all the files with a certain name (for example FileName) by last modification date but only the one with the last date. If there are two files with the same name and same modification date it should print the both. For example in this set... (6 Replies)
Discussion started by: KitFisto
6 Replies

8. Shell Programming and Scripting

Copy files based on modification date

How to copy files from a location to a directory <YYMM> based on last modification date? This will need to run daily. I want to copy those file for May to 0905 and Jun to 0906. Appreciate your guidance.:) Thanks. -rw-rw-rw- 1 ttusr tgrp 4514 May 29 21:49 AB24279J.lot_a... (17 Replies)
Discussion started by: KhawHL
17 Replies

9. UNIX for Dummies Questions & Answers

Sorting list of files per date column

Hi all, I have a pecular issue in sorting these files (not an ls -lrt) in Solaris environment. All the below files are modified on November 4th, but I want to sort these files as per date (eg: 01May07_1623 = ddmmmyy_hhmm) Nov 4 18:27 SONYELEC00.GI22973.01May07_1623.gpg Nov 4 18:27... (10 Replies)
Discussion started by: shivaastrogun
10 Replies

10. Shell Programming and Scripting

Sorting Files by date and moving files in date order

I need to build a k shell script that will sort files in a directory where files appear like this "XXXX_2008021213.DAT. I need to sort by date in the filename and then move files by individual date to a working folder. concatenate the files in the working folder then start a process once... (2 Replies)
Discussion started by: rebel64
2 Replies
Login or Register to Ask a Question