Senin, 07 November 2016

Mencari File dengan Text

To search for a string called “myFunction” in all text files located in /var/www/html/*.php use:
grep "myFunction" /var/www/html/*.php
 
To search recursively in all sub-directories you would alter the command by adding the -r option:
grep -r "myFunction" /var/www/html
 
Now you have probably noticed that grep prints out the matching lines containing your string, but you may also need the filenames of the files containing the string instead. You can use the -H option to narrow the output the filename followed by the line containing your search string, like so:
grep -H -r "myFunction" /var/www/html
This would output something like:
...
your_file.php: line containing myFunction
..
 
To print out just the filename you can cut command like this to clean the output further: (Note the one after the f, not an L)
grep -H -r "myFunction" /var/www/html | cut -d: -f1
The new cleaner out put would be like:
...
your_file.php
...

Sun

About Sun

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :