Thursday, 28 April 2016

how to find files and successfully search for items using a terminal command line

modern user interfaces I find are getting worse and worse at doing a basic file search.    here's a very simple way to search for files anywhere (locally or on a network volume etc)

find . -iname \*DVD\*


the . tells the find command to search starting at this point in your directory tree. ( by default you'll be in your home folder,   so you should navigate to where you want your search to start from )
-iname flag means case insensitive

the \* is a wildcard option for text before and/or after your text,   in my example above i'm saying find any file that has DVD in the title with words either before or after DVD.

the \ itself is an escape character,  which tells the terminal that the character directly after the \ should be treated literally and not as a parameter that needs processing.   a classic example of this in linux is that a blank space is typically ignored if you were trying to change your directory to a folder name 'folder name'.    in this scenario you need to cd into folder\ name which tells linux that the space you put after the \ should be taken literally as 'space'.   In the case of my find command above the \*  is telling the shell to process the * literally as a wildcard.

No comments:

Post a Comment