LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   finding a file (https://www.linuxquestions.org/questions/linux-newbie-8/finding-a-file-106648/)

pcdebb 10-21-2003 05:47 AM

finding a file
 
i have to find a file somewhere on the system. I've used the find file but get permission denied (find / -name filename -print) and i also used grep. My text only gives me these two ways to find files, so I don't know if maybe i'm not using the right flags or something on the find command?

jkobrien 10-21-2003 06:01 AM

try the find command as root.
Also try the locate command.

UltimaGuy 10-21-2003 06:09 AM

Try the "slocate <filename>" command, and it will give you a very comprehensive list indeed. It is also very fast, as it uses a small database, where it stores the details about the files.

pcdebb 10-21-2003 06:10 AM

actually i used find and found it mixed in all the lines of permission denied, but locate was one I found in my text also, thanx for you help tho, as I've entered these other commands in my growing notebook of notes :-)

yapp 10-21-2003 06:14 AM

The pemission denied messages are normal. If you're running as a normal user (and you should ;)) you're not allowed to access all files. The reasons vary from security issues to the privacy of other users at the system.

Something that gave me some problems with the find command:
* you need to use wildcards, to indicate there can be something before or after the name.
* the -name search is case-sensitive. Use -iname for incase-sensitive searching.

For example:
Code:

find /some/folder/ -iname "*file*"
You can also use the locate command to find something quickly.
'locate' uses a database created by 'updatedb'. In the crontab (or /etc/cron.*) folders, and "updatedb" is scheduelled to run every frequently.


Grep can be used to filter text from a steam, file, or search for text in files. You can supply a regular-expression for more advanced pattern searching.

for example:
Code:

grep -E "\((WW|EE)\)" /var/log/XFree86.0.log
The (WW|EE) expression selects WW or EE from the file. the \( and \) force grep to parse the text literally.

Grep can be used to search multiple files:
Code:

grep -i -R "some pattern" ...directories
grep -i "some pattern" ...file list

And select a certain pattern from a steam: (the pipe symbol redirects the output to 'grep')
Code:

ps aux | grep kde

edit: and to supress the error mesages: (redirect stderr;2 to /dev/null)
Code:

find /some/folder/ -name ...  2>/dev/null

pcdebb 10-21-2003 06:17 AM

i knew the exact name of the file, and i'm on a student server at school executing commands. He basically told us "create a symbolic link to filename, but you have to find it on your own", so I fished around until I found the way. Plus I have one of these "quick reference" card things and all the commands were right on there.

wow, I didnt expect so many responses at this hour, guess I'm not the only geek :D

jkobrien 10-21-2003 06:20 AM

Well, it is the World-Wide web ;-)

pcdebb 10-21-2003 06:23 AM

;)

Langly 10-21-2003 06:36 AM

hmm.. someone should mention whereis, it searches your path for the binaryfile,manpages and lib


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