$ ls | grep '[0-9]$'
It is essential that the $ symbol is placed after the paranthesis. This $ symbol will cause grep to look for the digits from 0 to 9 at the end of the filename.
A better way would be -
$ ls | grep '[[:digit:]]$'
Similarly, if you want to search for filenames that begin with a digit, here is the command -
$ ls | grep '^[0-9]'
or
$ ls | grep '^[[:digit:]]'
This will list all filenames that begin with a character.


0 comments:
Post a Comment