Linux - how to search for find and locate files and directories?
Hi, I need to learn how to search by file name and directory name in a Linux terminal. What I was looking at is using the find a locate command, but I don't understand how to use it. How could I search for this:
Any file named *FILE3*. *
Exactly a file named FILE3.mkv
Any directory named *DIR2*
Exactly a directory named DIR2
Hi,
here are a few examples of how to use find and locate to search through terminal linux:
# Any file named * FILE3 *. *
# Exactly the file named FILE3.mkv
# Any directory named * DIR2 *
# Exactly a directory named DIR2 (-name)
# Ignore uppercase and lowercase letters (-iname)
# Find files do not contain string
# Files smaller than 500MB
# Files larger than 7GB
# Find by file type (f - file, d - dir, b - block dev)
# Find and delete * .tmp files
# Find by time
- modified 3 days ago =
- accessed less than 2 days ago =
- changed metadata more than 7 days ago =
# Find - more options are found by:
-
-
-
# Find - additional parameters
- search depth
- Follow the
- Optimalization (1, 2, 3) of
The locate command uses db, so searching should be faster than find, but it can't do that much like find
#Installation locate
#update db for locate
# status db
# Existing files only
Any file named *FILE3*. *
Exactly a file named FILE3.mkv
Any directory named *DIR2*
Exactly a directory named DIR2
REPLY
Hi,
here are a few examples of how to use find and locate to search through terminal linux:
Find
# Any file named * FILE3 *. *
find /home -name "FILE3. *" # Exactly the file named FILE3.mkv
find /home -name "FILE2.mkv" # Any directory named * DIR2 *
find /home -type d -name "* DIR2 *" # Exactly a directory named DIR2 (-name)
find /home - type d - name "DIR2" # Ignore uppercase and lowercase letters (-iname)
find /home -type d-in "DIR2" # Find files do not contain string
find /home \! -name "string" # Files smaller than 500MB
find /home -size -500M # Files larger than 7GB
find /home -size + 7G # Find by file type (f - file, d - dir, b - block dev)
find /home - type l # Find and delete * .tmp files
find /tmp -name "* .tmp" -delete # Find by time
- modified 3 days ago =
find /home + mtime 3 - accessed less than 2 days ago =
find /home -atime -2 - changed metadata more than 7 days ago =
find /home -ctime +7 # Find - more options are found by:
-
-user -
-group -
-perm permissions# Find - additional parameters
- search depth
-maxdepth 4 - Follow the
-L symbols- Optimalization (1, 2, 3) of
-O3 Locate
The locate command uses db, so searching should be faster than find, but it can't do that much like find
#Installation locate
apt install mlocate #update db for locate
updatedb # status db
locate -S locate FILE3 locate -b FILE3 # Existing files only
locate -e FILE3