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 he
Find from root path find / -name "index.html"
Find from current path find . -name "index.html"
find /the_path_you_want_to_find -name index.html
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 /
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
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.
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.
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