Find usage in linux

From vpsget wiki
Revision as of 14:14, 9 September 2013 by Ndi (talk | contribs) (Created page with "Here is a few samples how to find files from command line. 1. When you need to find file by filename on whole drive find / -name "<somename>" in specified folder find /e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Here is a few samples how to find files from command line.

1. When you need to find file by filename on whole drive

find / -name "<somename>"

in specified folder

find /etc -name "<somename>"

find all files than contain specified string in filename

find / -name "*<somename>*"


2.when you need to find some text in files

search for a string called 'strsearch' in all text (*.txt) files located in /home/usr directory, use:

  grep "strsearch" /home/usr/*.txt

Search all subdirectories recursively

 grep -r "strsearch" /home/usr/

or

 grep -R "strsearch" /home/usr/

the grep command prints the matching lines. Use -H option to print the filename for each match:

$ grep -H -r "strsearch" /home/ndi