Operating System - HP-UX
1830207 Members
3821 Online
109999 Solutions
New Discussion

how do you search for a file?

 
bob the spod
Occasional Advisor

how do you search for a file?

if I have lost a file (which I have) and have not got a clue which directory it is in what command can I use?
for example's sake lets say the file is called cheesychips

also if I did know which directory whats the correct command then?

cheers for any help
bob
you make me feel like dancing (gonna dance the night away!)
10 REPLIES 10
Steven E. Protter
Exalted Contributor

Re: how do you search for a file?

find / -name cheesychips

If you have an idea what filesystem its on, say opt, you can go.

find /opt -name cheesychips

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hari Kumar
Trusted Contributor

Re: how do you search for a file?

find . -name cheesychips (or)

find / -name cheesychips

Information is Wealth ; Knowledge is Power
Sergejs Svitnevs
Honored Contributor

Re: how do you search for a file?

# /usr/bin/find / -name cheesychips

Regards,
Sergejs
Mark Grant
Honored Contributor

Re: how do you search for a file?

"find / -name cheesychips -print" if you have no idea where is is or replace the "/" with a directory to start searching for.

You can replace cheesychips with "*chips" or "ch*s*ch*" to get all files that match that pattern.

Now if using a pattern instead of a whole file name I surround it with quotes (as above) but some people don't. I do because I have no idea how the shell can possibly not expand that before running the command and therefore don't believe it really does work if you don't put quotes around it (evidence to the contrary)
Never preceed any demonstration with anything more predictive than "watch this"
Patrick Wallek
Honored Contributor

Re: how do you search for a file?

If you want to search the entire system:

# find / -name cheesychips -type f

The above will look through the entire system for a file (-type f) of name cheesychips.

# find /dir -name cheesychips -type f

The above will look through the specified dir for the file named cheesychips.

There are numerous options to find. Do a 'man find' for more info.
Bruno Ganino
Honored Contributor

Re: how do you search for a file?

Try
find / -name cheesychips -type f -print
or
cd /
find . -name cheesychips -print

Bruno

Torino (Turin) +2H
GK_5
Regular Advisor

Re: how do you search for a file?

find / -name cheesychips -print
Will search the entire dir structure for this file

-GK-
IT is great!
doug mielke
Respected Contributor

Re: how do you search for a file?

the only thing to add is a friendly grep afterwards, if not certain of the file name.

more system load, but easier syntax than find.


find / -print | grep heesy
Bill Hassell
Honored Contributor

Re: how do you search for a file?

Be VERY careful in using find / on a big server. Unless you were the root user, there should very few places you can create a file. The reason is that you don't have permission to store anything in /etc or /sbin or /opt, etc, so no need to look there. But what is worse is that find / will look at every file in a mounted CDROM, every file in NFS directories and through thousands (millions?) of files that are part of web pages or database files or unrelated applications. And since find will be running full speed, during the search time EVERYONE on the system can be affected by the massive number of directory accesses that will be taking place. Start with reasonable locations and use your shell history ($HOME/.sh_history) to see where you've been as far as directory changes Hint:

fc -l 1 | grep cd
fc -l 1 | grep lostfilename

BTW: if you don't have a hitory file, turn this on immediately to avoid similar situations. In /etc/profile, add these two lines:

export HISTFILE=$HOME/.sh_history
export HISTSIZE=500


Bill Hassell, sysadmin
Bruno Ganino
Honored Contributor

Re: how do you search for a file?

Bob, I add....
The option "-user" bound the command "find" can be used ... example: I want to find all the file-names that they begin with "chee" and that they belong to the user "bruno".

find / -name chee* -user bruno -print

Bruno
Torino (Turin) +2H