I am trying to find where index.html
is located on my linux server, and was wondering if there was a command to do that. Very new to linux and appreciate any help I can get.

- 3,807
- 3
- 33
- 50

- 1,159
- 5
- 15
- 19
-
4`man find`: http://unixhelp.ed.ac.uk/CGI/man-cgi?find. This isn't immediately programming-related; try http://linux.stackexchange.com. – Matt Ball Sep 18 '11 at 04:46
-
Searching from / would take a few days to complete. And spit out a bunch of (non-critical) errors for certain types of files while searching. Not the most efficient. – chown Sep 18 '11 at 04:54
-
1Please do some minimum research before posting question. – Praveen Sripati Sep 18 '11 at 05:20
-
6Several years later, Googling "find file in linux" gives this as a top 10 result. I'm sure glad the question was asked and answered. – Adrian Carr Jun 13 '17 at 16:29
-
you can try with locate as well – Channa Oct 13 '19 at 20:00
-
This question is a duplicate of [How can I recursively find all files in current and subfolders based on wildcard matching?](https://stackoverflow.com/q/5905054/11725753) – EvgenKo423 Jul 06 '21 at 17:20
6 Answers
Find from root path find / -name "index.html"
Find from current path find . -name "index.html"

- 3,765
- 1
- 25
- 32
-
Is this recursive by default? I'm used to seeing `-r` on commands. – Kellen Stuart May 11 '23 at 14:46
The below line of code would do it for you.
find / -name index.html
However, on most Linux servers, your files will be located in /var/www or in your user directory folder /home/(user) depending on how you have it set up. If you're using a control panel, most likely it'll be under your user folder.

- 200
- 1
- 8
-
Ah, liked stated below, the find program might take a while to complete... I'm not aware of any other option... – Taylor Jasko Sep 18 '11 at 04:52
Try this (via a shell):
update db
locate index.html
Or:
find /var -iname "index.html"
Replace /var with your best guess as to the directory it is in but avoid starting from /

- 51,908
- 16
- 134
- 170
-
All other answers suggest using `find` (well, this answer also suggests using `find` but only after `locate`), however, after several months of using `find` I realise `locate` is more convenient indeed! By the way, what is `update db`? Do I need it? – shintaroid Jul 16 '19 at 07:15
-
1@shintaroid locate does not actually search on your files system for a given file. What it does is it caches the information about the files into a database which is refreshed by a job on a given time interval. So what updatedb does is just to update the database manually. – Ivan Kaloyanov Oct 07 '19 at 06:34
Solution: Use unix command find
The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the 'primaries' and 'operands') in terms of each file in the tree.
- You can make the find action be more efficient and smart by controlling it with regular expressions queries, file types, size thresholds, depths dimensions in subtree, groups, ownership, timestamps , modification/creation date and more.
- In addition you can use operators and combine find requests such as or/not/and etc...
The Traditional Formula would be :
find <path> -flag <valueOfFlag>
Easy Examples
1.Find by Name - Find all package.json
from my current location subtree hierarchy.
find . -name "package.json"
2.Find by Name and Type - find all node_modules
directories from ALL file system (starting from root hierarchy )
sudo find / -name "node_modules" -type d
Complex Examples:
More Useful examples which can demonstrate the power of flag options and operators:
3.Regex and File Type - Find all javascript controllers variation names (using regex) javascript Files only in my app location.
find /user/dev/app -name "*contoller-*\.js" -type f
-type
f means file -name
related to regular expression to any variation of controller string and dash with .js
at the end
4.Depth - Find all routes patterns directories in app directory no more than 3 dimensions ( app/../../.. only and no more deeper)
find app -name "*route*" -type d -maxdepth 3
-type
d means directory -name
related to regular expression to any variation of route string -maxdepth
making the finder focusing on 3 subtree depth and no more <yourSearchlocation>/depth1/depth2/depth3
)
5.File Size , Ownership and OR Operator - Find all files with names 'sample' or 'test' under ownership of root user that greater than 1 Mega and less than 5 Mega.
find . \( -name "test" -or -name "sample" \) -user root -size +1M -size -5M
-size
threshold representing the range between more than (+) and less than (-) -user
representing the file owner -or
operator filters query for both regex matches
6.Empty Files - find all empty directories in file system
find / -type d -empty
7.Time Access, Modification and creation of files - find all files that were created/modified/access in directory in 10 days
# creation (c)
find /test -name "*.groovy" -ctime -10d
# modification (m)
find /test -name "*.java" -mtime -10d
# access (a)
find /test -name "*.js" -atime -10d
8.Modification Size Filter - find all files that were modified exactly between a week ago to 3 weeks ago and less than 500kb and present their sizes as a list
find /test -name "*.java" -mtime -3w -mtime +1w -size -500k | xargs du -h

- 12,197
- 3
- 67
- 61
In general, the best way to find any file in any arbitrary location is to start a terminal window and type in the classic Unix command "find":
find / -name index.html -print
Since the file you're looking for is the root file in the root directory of your web server, it's probably easier to find your web server's document root. For example, look under:
/var/www/*
Or type:
find /var/www -name index.html -print

- 114,292
- 17
- 138
- 190