In Unix, how can I tell if files are used by my web pages?

In Unix, you can use the grep command to see if a file is referenced in your web pages. This will work only for files in the current directory, so you will have to do this, one at a time, with each directory in which you have web pages. If you are concerned about links in files on other accounts or computers, you will have to do the same in each of those as well.

The grep command searches through one or more files for a particular string of text. Since links to files must contain the filename, if you use the grep command for the file's name in all of the files that might contain links to it, you will be able to see if those links exist.

The general syntax for the grep command is:

   grep pattern filenames

Replace pattern with the name of the file you are searching for. Replace filenames with the names of files in which to look for links. If you use * (an asterisk) to replace filenames, it will search all of the files in the current directory. For example, if you want to see if any of the files in your top level www directory contain a link to a file called junkpic.gif, you could enter the following commands:

  cd ~/www 
  grep junkpic.gif *

You could expect output similar to the following:

  file1.html:<img src="http://php/~username/Gifs/junkpic.gif">junk.gif<br> 
  file2.html:<img src="http://php/~username/Gifs/junkpic.gif.old">junk.gif.old

The portion before the first colon in each line is the name of the file in which the search string was found. The rest of the line is the full text of the line in that file where the string was found.

For more information about using the grep command, as well as its variants fgrep and egrep, see What is grep, and how do I use it? For further information, enter at the Unix prompt:

  man grep 

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document aeer in the Knowledge Base.
Last modified on 2017-05-16 11:41:16.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.