Find files with wrong date given filename

I have a directory with files whose names are common with a suffix of increasing date.

An example is:


representing the 5th of September.

These files are supposed to be created in the first few minutes of the next day, e.g. the above file should've been created at 00:01 on the 6th of September.

However, due to some bug with how the filenames are generated, an application has been saving them incorrectly. So files created at 00:16 on the 5th of September have the suffix 20120905, i.e. the filename is 1 day too late.

Output from ls -h showing the wrong naming:

2012-09-05 00:16 FH_lbm_dump.20120905

So logic to detect this would look at the file name, extract the date, and if its equal to the file timestamp it would be positive.

How can we do this in Bash / Perl / Python?


I will not solve your entire problem, but I'll give you a place to start. The rest is really up to you.


# loop through all filenames in current dir
for filename in *; do

    # How to extract the date from the file name

    # How to get the file's modification date in the same format
    date_modified=$(stat -c %y "$filename" | cut -d ' ' -f1 | sed 's/-//g')

    # test for inequality
    if [ $date_from_file -ne $date_modified ]; then

        ... # do your thing



Need Your Help

Comparing and merging modified files in github

git github

I worked on the master branch of a repository and I didn't commit the files for a while. By this time, most of the files have been modified. How can I compare and merge the files in git?

android facing nullpoint exception while Parsing json object from an url into listview

android listview android-arrayadapter json

I am trying to parse json object to populate it into list view,but i am facing some problem please help