简体   繁体   中英

How can i make alias for searching text inside files in linux

I want to make my custom alias for searching text inside the directory recursively. Currently i use this

grep -r "text to search" /var/www/sites

I want first

  1. To search only specific files like only html , php files only.
  2. I also want the line number of the file
  3. i want to make the alias of command like myalias so that from command line i use only this

myalias text-to-search (without quotes)

Is this possible

Put this in your ~/.bashrc:

wwwgrep() { 
    find /var/www/sites -name '*.php' -o -name '*.html' -exec grep -Hn "$1" {} \;
}

Then

wwwgrep <PATTERN>

Finally (to refresh your environment)

exec bash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM