MacOS – Mac Terminal “find” command : What does a double slash in the result output mean

findermacosterminal

I use the find-command for searching in large and nested directory-structures.

In the result-output is sometimes a double-slash ( // ) included.

Example (after "Downloads"):

#> find ~/Downloads/ -iregex ".*some.*"
/Users/michael/Downloads//subDirectory/some_file.pdf

I first thought it would mark the current working-directory. But that isn't the case.

What's the meaning of this double-slash?

Usually I copy the result into the clipboard, change to the finder. Then
"shift" + "command" + "g" and pasting the path (until the file) into the box. So that the containing directory is opened.

Works fine. But the double-slash I have to remove manually.

Therefore: How can I avoid it?

Best Answer

find is rather literal. When you tell it to search within "~/Downloads/", it uses that (including the trailing slash) as the prefix for whatever it finds. Since there's an unnecessary and irrelevant slash at the end of the path you gave it, you wind up with an unnecessary and irrelevant extra slash in the output.

Solution: remove the trailing "/" from the search directory:

#> find ~/Downloads/ -iregex ".*some.*"
/Users/michael/Downloads//subDirectory/some_file.pdf
#> find ~/Downloads -iregex ".*some.*"
/Users/michael/Downloads/subDirectory/some_file.pdf