LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2006, 10:43 PM   #1
xode
Member
 
Registered: Aug 2003
Distribution: Mandrake 9.0; FC4; FC8; SUSE 10.3; SUSE 12.1; SUSE 13.2
Posts: 636
Blog Entries: 1

Rep: Reputation: 51
Making find do search in a directory that has whitespace in its pathname


I would like to use find to do a search in the following directory:

/home/testuser/test1 test2 test3/

but haven't been able to get find to do it, since the "test1 test2 test3" directory name contains spaces and I haven't seen any documentation anywhere that shows how to get find to operate on directories that have pathnames containing whitespace. So far, I have tried:

find /home/testuser/test1 test2 test3 [search criteria]

--> find: /home/testuser/test1 no such file or directory
find: test2 no such file or directory
find: test3 no such file or directory

find '/home/testuser/test1 test2 test3' [search criteria]

--> find: '/home/testuser/test1 test2 test3' no such file or directory

find "/home/testuser/test1 test2 test3" [search criteria]

--> find: "/home/testuser/test1 test2 test3" no such file or directory
 
Old 04-17-2006, 10:48 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
If you wrap the directory name in quotes (single or double), or escape the spaces it will work. For example:
Code:
find "/home/testuser/test1 test2 test3"
find '/home/testuser/test1 test2 test3'
find /home/testuser/test1\ test2\ test3
 
Old 04-18-2006, 10:42 AM   #3
xode
Member
 
Registered: Aug 2003
Distribution: Mandrake 9.0; FC4; FC8; SUSE 10.3; SUSE 12.1; SUSE 13.2
Posts: 636

Original Poster
Blog Entries: 1

Rep: Reputation: 51
It now works. It turns out that you don't want to escape the '"s' when you feed them to find. Otherwise find sees them as part of the pathname and not the pathname boundary markers that you want them to be. What can really be confusing is that what appears to work directly on the command line doesn't work when put in a script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wxFileName +search all files in Directory bianchi Programming 1 12-27-2005 11:31 PM
making search more advanced perfect_circle LQ Suggestions & Feedback 2 06-13-2005 08:12 AM
openOffice template directory - what is the pathname? TSynergy Linux - Software 4 10-11-2004 09:53 PM
Java: Getting the contents of a search dialog box in text editor i am making ludeKing Programming 4 04-23-2004 08:46 PM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 04:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration