0

My websites file structure has gotten very messy over the years from uploading random files to test different things out. I have a list of all my files such as this:

file1.html
another.html
otherstuff.php
cool.jpg
whatsthisdo.js
hmmmm.js

Is there any way I can input my list of files via command line and search the contents of all the other files on my website and output a list of the files that aren't mentioned anywhere on my other files?

For example, if cool.jpg and hmmmm.js weren't mentioned in any of my other files then it could output them in a list like this:

cool.jpg
hmmmm.js

And then any of those other files mentioned above aren't listed because they are mentioned somewhere in another file. Note: I don't want it to just automatically delete the unused files, I'll do that manually.

Also, of course I have multiple folders so it will need to search recursively from my current location and output all the unused (unreferenced) files.

I'm thinking command line would be the fastest/easiest way, unless someone knows of another. Thanks in advance for any help that you guys can be!

4

1 回答 1

1

是的!这很容易做到grep。在这种情况下,您将运行如下命令:

$ for orphan in `cat orphans.txt`; do \
    echo "Checking for presence of ${orphan} in present directory..." ;
    grep -rl $orphan . ; done

orphans.txt 看起来像上面的文件列表,每行一个文件。如果你想不区分大小写,你可以添加-i到上面。grep您可能希望/var/www在您的发行版保留其 webroot 的地方或任何地方运行该命令。如果在您看到上面的“正在检查...”并且下面没有匹配项之后,您没有任何与该名称匹配的文件。

于 2013-10-23T06:02:41.190 回答