Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Double Slashes in Find Returns

Could anyone explain why find command returns double slashes and how to fix it?


For instance, say I wanted to retrieve all .txt files on a CD named "MY_CD".


If I do


$ find /Volumes/MY_CD/ -name "*.txt"


I get


/Volumes/MY_CD//file1.txt

/Volumes/MY_CD//file2.txt

/Volumes/MY_CD//file3.txt

.

.

.


but if I do


$ find /Volumes/MY_CD -name "*.txt"


I get the correct paths


/Volumes/MY_CD/file1.txt

/Volumes/MY_CD/file2.txt

/Volumes/MY_CD/file3.txt

.

.

.


So, if the path argument has a trailing slash, find returns double slashes in file paths, which looks to me like a bug.


Anyone knows how to fix it? This behaviour borks my scripts, which worked fine pre-SL, and I'd rather fix find than go through all my scripts to fix them.


Thanks.

Mac OS X (10.6.8)

Posted on Dec 12, 2011 3:36 PM

Reply
Question marked as Best reply

Posted on Dec 12, 2011 7:39 PM

So, if the path argument has a trailing slash, find returns double slashes in file paths, which looks to me like a bug.


Anyone knows how to fix it? This behaviour borks my scripts, which worked fine pre-SL, and I'd rather fix find than go through all my scripts to fix them

It's always done that. It basically uses the path argument specified as is.


And there should be nothing to fix. /a/b/c and /a//b//c are equally legal and both specify c. So if this, as you say "borked" your scripts then it's your scripts then you have a problem with the script, maybe errant quoting.

3 replies
Question marked as Best reply

Dec 12, 2011 7:39 PM in response to fane_j

So, if the path argument has a trailing slash, find returns double slashes in file paths, which looks to me like a bug.


Anyone knows how to fix it? This behaviour borks my scripts, which worked fine pre-SL, and I'd rather fix find than go through all my scripts to fix them

It's always done that. It basically uses the path argument specified as is.


And there should be nothing to fix. /a/b/c and /a//b//c are equally legal and both specify c. So if this, as you say "borked" your scripts then it's your scripts then you have a problem with the script, maybe errant quoting.

Dec 12, 2011 10:42 PM in response to X423424X

Thanks for your reply. You are right about find, and I was wrong. I thought the double slashes were the problem, because that's where the scripts failed, but they weren't. I'm also using a newer version of BBEdit, which until now hadn't caused any problems, but it looks like its handling of the POSIX file statement has changed, and that's what's causing the scripts to fail. So back to re-writing the scripts. This is so much fun…

Sep 22, 2016 9:31 AM in response to fane_j

GNU findutils' 'find' does not do this, so if you've used that at all, that might explain why macOS's (BSD's) double slashes appear strange to you.


You can "fix" it with a simple "| sed 's@//@/@'" which can easily be added to a wrapper.


You could also install GNU's findutils with 'brew install findutils' and then either use 'gfind' directly, alias 'find' to 'gfind', or add /usr/local/opt/findutils/libexec/gnubin to your path (which also adds GNU findutils' 'locate', 'updatedb', & 'xargs').

Double Slashes in Find Returns

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.