Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, i want to make my bash script search for this phrasse: header('Location: https://www.mysite.com/'); in all files smaller than 2000kb in /home and output their full paths into file ./result ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User postcd's Avatar
    Join Date
    Apr 2011
    Posts
    350

    searching for a phrasse in files and outputting file path to a file


    Hi, i want to make my bash script search for this phrasse:
    header('Location: https://www.mysite.com/');

    in all files smaller than 2000kb in /home and output their full paths into file ./result

    so i have this:

    Code:
    phrasse="header('Location: https://www.mysite.com/');"
    
    find /home -type f -size -2000k -print | xargs grep *"$phrasse"* -ls -exec "pwd;ls -lah >> ./result" {} \;
    But when i execute that command, it start listing alot of files on the screen as the search goes, but these files dont contain the phrasse i want to search. Please what is wrong in my command? (i want to run it as a cronjob)

    thank you in advance for any help

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    use find's built-in exec capability instead, e.g.:

    Code:
    find /home -type f -size -2000k -exec grep -l "$phrasse" {} \; >> ./result

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •