Linux/MacOSX : Search for files by filename and extension with find command
Jotting down these useful commands here for future references, never know when I might need to recall them again on how to search for files by filename or extension.
To search current directory and directories under the current directory for files with .go
extension :
>find ~ -type f | grep "\.go$"
Sample output :
/Users/admin/variables.go
/Users/admin/writebyte.go
/Users/admin/writerune.go
/Users/admin/writestring.go
/Users/admin/x509.go
If need to search for more than 1 type of file extension, use grep -E
command to combine the extensions. For instance, to search current directory and directories under the current directory for files with .go
, .py
and .php
extensions :
>find ~ -type f | grep -E "\.go$|\.py$|\.php$"
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+18.5k Golang : How to make function callback or pass value from function as parameter?
+13k Golang : Generate Code128 barcode
+9.8k Golang : How to get quoted string into another string?
+7k Golang : Check to see if *File is a file or directory
+6.3k Golang : Find the longest line of text example
+5.6k Golang : Shuffle array of list
+14.1k Golang : GUI with Qt and OpenCV to capture image from camera
+51.5k Golang : How to get time in milliseconds?
+9.9k Golang : cannot assign type int to value (type uint8) in range error
+19.4k Golang : Append content to a file
+8.7k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+5.9k Golang : Scan forex opportunities by Bollinger bands