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
+7.5k Golang : Gorrila set route name and get the current route name
+7.8k Golang : How to execute code at certain day, hour and minute?
+14.9k Golang : Get URI segments by number and assign as variable example
+11.7k Golang : Fuzzy string search or approximate string matching example
+15.4k Golang : Get query string value on a POST request
+5.8k Fix yum-complete-transaction error
+9.9k Golang : Get current, epoch time and display by year, month and day
+8.8k Golang : Find duplicate files with filepath.Walk
+6.1k Javascript : Get operating system and browser information
+29.6k Golang : How to create new XML file ?
+7k Golang : Calculate BMI and risk category
+6.8k Golang : Derive cryptographic key from passwords with Argon2