Shell Finding Files
Finding a file means searching folders for a file by its name. The find command searches a folder and all the folders inside it.
Find one file by name
find searches the current folder and all inside it.
find . -name "notes.txt" | sortFind all text files in a folder
*.txt matches every file whose name ends in .txt.
find docs -name "*.txt" | sortFind all photos
*.jpg matches every file whose name ends in .jpg.
find photos -name "*.jpg" | sortFind a file type
*.csv matches every file whose name ends in .csv.
find . -name "*.csv" | sortExample
find . -name "*.txt" | sortKey points
- find: a command that searches for files by name.
- Use find with a folder name to search that folder and all inside it.
- Use -name with a pattern in quotes to search for a name.
- A pattern is a name with * in it, and * matches any letters.
- sort: a command that puts lines in order.
- Send the find output to sort with |, so the order stays the same every time.
In this example, find searches the current folder and all inside it. The pattern "*.txt" matches every file whose name ends in .txt. Then sort puts the five lines in the same order every time.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command finds every .txt file under the current folder?