Business and technology shouldn't be difficult

How to search files by extension in Linux?

Published by Atul Kumar Pandey on December 13, 2021.

Want to search files using a file extensions like: *.css, *.js, *.php, *.txt, or *.zip etc. in Linux.

Use the following command.

sudo find /home/user/Documents -type f -name "*.css"

Let’s understand the above command.

  • sudo enables administrative access.
  • find is a find, query, or search instruction.
  • /home/user/Documents is working directory or a directory where you want to find things.
  • -type f instructs to look for files only.
  • -name “input search term” will search for file name based on your input search term. It is a base of the file name (the path with the leading directories removed) that matches the shell pattern.
  • -iname “input search term” is the same as a -name except file names are not case sensitive. For example, ‘style.css’ will match STYLE.css, Style.css, Style.Css, and so on.

Notes:

  • Usually, administrative access is not required for the basic searches.
  • You can use an asterisk symbol in the input search term for dynamic search.

Have any doubts? Feel free to leave a comment in the comment section below.

Categorized in Technology and tagged in , .

Published by Atul Kumar Pandey

Atul Kumar Pandey is a creator of atulhost. Being a business management graduate, he has a flair for business writing but also likes to dabble in technological trends. He is a voracious reader and an avid tech tester and loves to try new things.

Leave a reply

Required fields are asterisked and email address will not be shared.