Find the answer to your Linux question:
Results 1 to 7 of 7
Hi I'm new to linux and linux command. I have sites that been hacked and need to overwrite some files that been modified by hacker. How can I find files ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    Find and Repace File

    Hi

    I'm new to linux and linux command. I have sites that been hacked and need to overwrite some files that been modified by hacker.

    How can I find files "index.php" in a subfolders of \home and replace with 'index.php' file in the root ? Much appreciate.


    Thank you.

    Loh

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    use the find command. check the man page for more
    Code:
    find /home/ -type d -exec cp "/root/index.html" "{}" \;

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    Will this command overwrite all index.html files in the /home subfolders?

    "/root/index.html" copy to "/home/sub1/index.html"
    "/root/index.html" copy to "/home/sub1/sub2/index.html"

  4. #4
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    103
    Hi,

    For locating giles I use "locate". Run "updatedb" first, that will update your database of files, then use locate as follows:
    "locate filename"
    That will give you a list of all files in the entire file system with a matching name.

    Dave

  5. #5
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    After reading some tutorial, I think this should work.

    What I'm trying to do is copy index file from source to subfolders to overwrite the existing files.
    "/home/source/index.html" copy to "/home/sub1/index.html"
    "/home/source/index.html" copy to "/home/sub1/sub2/index.html"

    Do I miss anything?

    Code:
    find /home/dest -type f -name "index.html" -exec cp /home/source/index.html {} \;

  6. #6
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    103
    Hi,

    I'm not qualified to check that, sorry... I would use "cp "source" "destination". That should overwrite. Be sure to make a backup of the original files you want to save... I am as new at this as you are...

    Dave

  7. #7
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Quote Originally Posted by loh32 View Post
    After reading some tutorial, I think this should work.

    What I'm trying to do is copy index file from source to subfolders to overwrite the existing files.
    "/home/source/index.html" copy to "/home/sub1/index.html"
    "/home/source/index.html" copy to "/home/sub1/sub2/index.html"

    Do I miss anything?

    Code:
    find /home/dest -type f -name "index.html" -exec cp /home/source/index.html {} \;
    Look right to me. The thing that I sometimes do to verify I have it right is run it with 'echo' before the command so you can see what will be executed when you actually do run it.

    Code:
    find /home/dest -type f -name "index.html" -exec echo cp /home/source/index.html {} \;

Posting Permissions

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