In Unix, determine if files are used by your 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 About grep For further information, enter at the Unix prompt:

man grep

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document aeer in the Knowledge Base.
Last modified on 2023-07-14 09:04:37.