Find usage in linux

From vpsget wiki
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/


 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