I want to list out the files which starts with a number and ends with ".c" extension. The following is the find command which is used. But, it does not give the expected output.
Command:
find -type f -regex "^[0-9].*\\.c$"
It's because the regex option works with the full path and you specified only the file name. From man find
:
-regex pattern File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named './fubar3', you can use the regular expression '.*bar.' or '.*b.*3', but not 'f.*r3'. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.
Try with this:
find -type f -regex ".*/[0-9][^/]+\.c$"
where you explicitly look for a string where "the format of your filename follows any string that terminates with a slash"
UPDATE: I made a correction to the regex. I changed .*
in the filename to [^\]+
as after "any string that terminates with a slash" we don't want to find a slash in that part of the string because it wouldn't be a filename but another directory!
NOTE: The matching .*
can be very harmful...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments