Lesson 2 of 35
Lesson Progress: 0%
The find command searches for files and directories in a directory hierarchy. You give it a starting path and criteria such as name, type, or size, and it finds every matching item. Unlikelocate, find searches the live filesystem and supports powerful filters and actions. Use find when you need fine-grained control over what to search for and what to do with the results.
find . -name "*.txt" searches the current directory for files ending in .txt.. means "start in the current directory".-name option matches filenames using a pattern.locate, find searches live and does not use a database.find /home -name "*.md" searches the /homedirectory for Markdown files.-name pattern *.md matches all files ending in .md.find . -type d finds only directories, not regular files.-type d filter restricts results to directories.-type f to find only regular files.find . -size +1M finds files larger than 1 megabyte.+ prefix means "greater than".k, M, andG for kilobytes, megabytes, and gigabytes.find . -empty finds empty files and directories.-empty flag matches both empty regular files and empty directories.find . -name "*.txt" -exec rm \; finds all.txt files and deletes them.-exec option runs a command on every matching file. is a placeholder that represents each found file.\; marks the end of the -exec command.Test Incomplete
~$ find . -name "*.txt"~$ find /home -name "*.md"~$ find . -type d~$ find . -size +1M~$ find . -empty~$ find . -name "*.txt" -exec rm {} \;