I have files fileName_1, fileName_2 ... fileName_100000 where the fileNames are numbered sequentially. How can I delete the files of index greater than, say 100?
If filenames are numbered sequentially just run the following command:
You may try this command also,
It will delete all the files(ranges from 100 to 100000) if the filename contains numbers in an sequential order.
In general you have several ways to achieve this:
will be expanded by the shell into roughly 100,000 filenames. If the basename is a long path and the number is high enough, you might actually exceed the maximum length of a command line with this approach.
does not suffer from this problem, but is a relatively slow way of deleting the files, as the shell has to perform the variable substitution and launching rm about 100,000 times.
Both methods above might cause warnings if some of the files, say
Usually, solutions based on
will still launch the
However, always check first if the pattern actually matches the files that you want to target:
So in this case you'd delete a file you wanted to keep and left the files that should have been removed.
Use the following command:
That will delete files from 100 to 100000 .
More information: Site