PDA

View Full Version : [all variants] [SOLVED] questions about command 'find'



Stefanie
May 7th, 2008, 04:55 PM
i've got a question about the command find. i want to look for a file named "test.tex", and the terminal should automatically go to the path of the directory where that file can be found

so i type


find ~ -name 'test.tex' -execdir cd '{}' \+


but the output is:


find: cd: No such file or directory


what am i doing wrong?

subzero316
May 7th, 2008, 05:20 PM
If you want to find in which directory then be simple n use


find -name 'filename'
this will scan current dir and subdir


From the root then use,

find / -name 'filename'

Stefanie
May 7th, 2008, 05:27 PM
i know, but i want the terminal to go to the path of the directory.

Monicker
May 7th, 2008, 05:40 PM
I'm not familiar with -execdir, but this works for me


cd `find ~ -name 'file.txt' -printf %h`

Stefanie
May 7th, 2008, 06:32 PM
thanks, but it doesn't work when the directory names contain spaces... :-(

crashie
May 7th, 2008, 06:39 PM
You need to put the directory name (which is generated by `find ...` in this case) inside quotes:


cd "`find ~ -name 'file.txt' -printf %h`"

Stefanie
May 7th, 2008, 06:42 PM
thanks a lot! where can i find out more about this stuff? i don't find the manual pages very helpful...

Monicker
May 7th, 2008, 07:37 PM
thanks a lot! where can i find out more about this stuff? i don't find the manual pages very helpful...


You could start with these links:

http://tldp.org/LDP/Bash-Beginners-Guide/html/

http://tldp.org/LDP/abs/html/


Just browsing through the examples in the 2nd one can you give you lots of ideas. You could also see if your library has a copy of "Bash Cookbook".