Saturday, April 19, 2014

how to find on linux

Find is a realy fast and convenient way to search through your filesystem. To find any file by name just type:

[sudo] find -name 'name_of_file'

sudo is required if you're seeking in the directories you don't own. Flag means searching by name. Words in single quotation marks are the name of the files you search. Like almost everytime in linux, you can use regular expression as a keyword for find.
Like, if you wanted to find a file but didn't remember it's name except 2 first letters:

[sudo] find -name 'na*'

Just a short reference for regexps:
* replaces any kind of character of any quantity.
? replaces any single char
for more detailed reference 

The second most often used flag using find for me is -type d, which means you want to find a directory:

[sudo] find -type d -name 'fooDir*'

and this command finds any dir in within the pwd(present working directory) which name is fooDir(any amount of any chars here).

For more detailed reference do  

man find

No comments:

Post a Comment