How to delete files if a numerical part of their name is greater than a given number?

laurent

I've got files like this:

cap_20151023T122915_791033959.png
cap_20151023T122918_946392456.png
cap_20151023T122920_227637228.png
cap_20151023T122920_875467456.png

and I would like to use the find command to delete those greater than, for example, cap_20151023T122919*, which would result in the deletion of cap_20151023T122920_227637228.png and cap_20151023T122920_875467456.png.

Is there any way to do this, preferably with a single find command?

don_crissti

With zsh and <[x]-[y]> glob operator (matches numbers in the range x to y, inclusive; either of the numbers may be omitted to make the range open-ended) e.g.:

print -rl -- **/cap_20151023T<122920->_*

or, if you want to select only the file names in the 122920-999999 range:

print -rl -- **/cap_20151023T<122920-999999>_*

so with file names like:

tmp/cap_20151023T122915_791033959.png
tmp/cap_20151023T122915791_959.png
tmp/cap_20151023T122918_946392456.png
tmp/cap_20151023T122920_227637228.png
tmp/cap_20151023T1229205_875467456.png
tmp/cap_20151023T122920_875467456.png
tmp/cap_20151023T122980_227637228.png

the first one prints:

tmp/cap_20151023T122915791_959.png
tmp/cap_20151023T122920_227637228.png
tmp/cap_20151023T1229205_875467456.png
tmp/cap_20151023T122920_875467456.png
tmp/cap_20151023T122980_227637228.png

while the second one prints:

tmp/cap_20151023T122920_227637228.png
tmp/cap_20151023T122920_875467456.png
tmp/cap_20151023T122980_227637228.png

If you're happy with the result replace print -rl with rm -f

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL delete all rows where id is greater than the given number

From Dev

How to move all files matching a certain name to a new folder if the number of matching files is greater than 10?

From Dev

find files that have number in file name greater than

From Dev

Linux How to List Files greater than particular timestamp in file name?

From Dev

Find number greater than given parameter in regex

From Dev

smallest number greater than given number which is a palindrome

From Dev

max. distance of a number greater than a given number in array

From Dev

How do I delete all files with a given name in all subdirectories?

From Dev

How to delete all lines in text file that is NOT a number greater than a specific value? (Including strings)

From Dev

Number of Subarray whose sum greater than given value

From Dev

List files in ascending order and greater than a given value

From Dev

How to find the list of consecutive elements in a random list where the resultant list should not have greater number than the given number

From Dev

How to delete lines where the given part of the line is more than 100 chars?

From Dev

How do I print values in a list that are greater than a certain number along with the row name in R?

From Dev

How to find files greater than a size in linux

From Dev

Windows shell command to delete numbered files greater than n

From Dev

Listing files greater than particular timestamp in file name?

From Dev

how to get data greater than and less than a number in codeigniter

From Dev

Ant/Groovy: How to delete files over than given date, but keep a maximum of 3

From Dev

How to rename a specific colname by name in a Matrix, rather than numerical index?

From Dev

How can I find files with more than one line in them with a given name?

From Dev

How to perform "greater than" with sed or awk to delete specific lines?

From Dev

How to perform "greater than" with sed or awk to delete specific lines?

From Dev

How can I find and delete all files in subfolders by matching part of the file name

From Dev

How to get a number higher than a given value

From Dev

Delete files older than given time from directory

From Dev

Binary tree - Delete nodes whose level is greater or equal than given one

From Dev

AppleScript less than number or greater than number

From Dev

Linux: How can I delete all files whose file name is more than X characters in length?

Related Related

  1. 1

    MySQL delete all rows where id is greater than the given number

  2. 2

    How to move all files matching a certain name to a new folder if the number of matching files is greater than 10?

  3. 3

    find files that have number in file name greater than

  4. 4

    Linux How to List Files greater than particular timestamp in file name?

  5. 5

    Find number greater than given parameter in regex

  6. 6

    smallest number greater than given number which is a palindrome

  7. 7

    max. distance of a number greater than a given number in array

  8. 8

    How do I delete all files with a given name in all subdirectories?

  9. 9

    How to delete all lines in text file that is NOT a number greater than a specific value? (Including strings)

  10. 10

    Number of Subarray whose sum greater than given value

  11. 11

    List files in ascending order and greater than a given value

  12. 12

    How to find the list of consecutive elements in a random list where the resultant list should not have greater number than the given number

  13. 13

    How to delete lines where the given part of the line is more than 100 chars?

  14. 14

    How do I print values in a list that are greater than a certain number along with the row name in R?

  15. 15

    How to find files greater than a size in linux

  16. 16

    Windows shell command to delete numbered files greater than n

  17. 17

    Listing files greater than particular timestamp in file name?

  18. 18

    how to get data greater than and less than a number in codeigniter

  19. 19

    Ant/Groovy: How to delete files over than given date, but keep a maximum of 3

  20. 20

    How to rename a specific colname by name in a Matrix, rather than numerical index?

  21. 21

    How can I find files with more than one line in them with a given name?

  22. 22

    How to perform "greater than" with sed or awk to delete specific lines?

  23. 23

    How to perform "greater than" with sed or awk to delete specific lines?

  24. 24

    How can I find and delete all files in subfolders by matching part of the file name

  25. 25

    How to get a number higher than a given value

  26. 26

    Delete files older than given time from directory

  27. 27

    Binary tree - Delete nodes whose level is greater or equal than given one

  28. 28

    AppleScript less than number or greater than number

  29. 29

    Linux: How can I delete all files whose file name is more than X characters in length?

HotTag

Archive