1

why 'save$' can not match the file named save?

root@debian:/home/tiger# ls /home/test
save
root@debian:/home/tiger# find /home/test -regex 'save$'
root@debian:/home/tiger# find /home/test -regex '.*save$'
/home/test/save
2
  • This question is about "software tools commonly used by programmers", so I think it should be reopened. Commented Sep 12, 2014 at 17:02
  • The question could be reworded like this: Why does find DIR -regex treat the regex as if it always had a leading ^ anchor and a trailing $ anchor? Commented Sep 12, 2014 at 17:13

1 Answer 1

1

Because the regex is matched against the full path(i.e. /home/test/save) instead of just on the file name 'save'.

Sign up to request clarification or add additional context in comments.

1 Comment

usually you need the ^ and $ anchors to match on the whole string, and, as the example by the OP shows, the $ is allowed. But it's as if there were an implicit ^ too. The question remains: Why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.