bashdatabase-management

How do I find files with a greater numerical value than a file based upon timestamp in the filename


New to Linux and bash shell scripting so any assistance would be greatly appreciated.

Edit:

I'm looking to find all files in a directory with a greater numerical filename than another filename uising a bash shell script.

The filename being used for comparison: Jimmy_1_2019-05-11-070001.csv

My Files :

 Jimmy_1_2019-05-11-094501.csv
 Jimmy_1_2019-05-11-093001.csv
 Jimmy_1_2019-05-11-091501.csv 
 Jimmy_1_2019-05-11-090001.csv 
 Jimmy_1_2019-05-11-070001.csv

I want my output to look like this:

 Jimmy_1_2019-05-11-094501.csv
 Jimmy_1_2019-05-11-093001.csv
 Jimmy_1_2019-05-11-091501.csv
 Jimmy_1_2019-05-11-090001.csv

Solution

  • X='Jimmy_1_2019-05-11-070001.csv'
    for n in `ls`; do   # run this in the folder with your files
      if [[ $n > $X ]]; then
        echo $n;
      fi;
    done
    

    Example:

    > ls
    Jimmy_1_2019-05-11-070001.csv  Jimmy_1_2019-05-11-091501.csv  Jimmy_1_2019-05-11-094501.csv
    Jimmy_1_2019-05-11-090001.csv  Jimmy_1_2019-05-11-093001.csv
    
    > ./../so1.sh 
    Jimmy_1_2019-05-11-090001.csv
    Jimmy_1_2019-05-11-091501.csv
    Jimmy_1_2019-05-11-093001.csv
    Jimmy_1_2019-05-11-094501.csv