# How to check for un-linked/dead files in \_site

**URL:** <https://talk.jekyllrb.com/t/how-to-check-for-un-linked-dead-files-in-site/7673>\
**Category:** Share\
**Created:** [September 19, 2022, 12:36pm UTC](https://talk.jekyllrb.com/t/how-to-check-for-un-linked-dead-files-in-site/7673 "2022-09-19T12:36:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [September 19, 2022, 12:36pm UTC](https://talk.jekyllrb.com/t/how-to-check-for-un-linked-dead-files-in-site/7673/1 "2022-09-19T12:36:34Z")

</div>

Over in the “[Core feature wishlist](https://talk.jekyllrb.com/t/core-feature-wishlist/7655/7)” topic, @michaelbach mentioned wanting a way to detect dead or un-linked files in Jekyll generated site. I too wanted to check for dead files, and found a relatively simple way to do it for Jekyll sites with `wget` and `diff` (wget is available from most package managers: homebrew, apt, etc).

Run the following commands from a site’s source directory while `bundle exec jeykll serve` is running (i.e. in another terminal window):

```nohighlight
wget -r -nv -nH -P /tmp/sitecopy http://127.0.0.1:4000
diff -r _site /tmp/sitecopy

```

Wget makes a recursive copy of all files reachable from the site’s root into a temp directory. Then diff recursively compares it to the generated `_site` directory. Here are the same commands with human-readable switches:

```nohighlight
wget --recursive --no-verbose --no-host-directories \
     --directory-prefix=/tmp/sitecopy http://127.0.0.1:4000
diff --recursive _site /tmp/sitecopy

```

The resulting output (below) shows un-linked files. Not all unlinked files are “dead”. For example below, the custom 404 page is live (on Github Pages), and the CSS map is for debugging. These can be excluded from the diff (second run below). The last file remaining, `assets/minima-social-icons.svg`, is un-linked and unused/dead, so it could be removed from the site (via `_config.yml` exclude):

```nohighlight
$ diff --recursive _site /tmp/sitecopy
Only in _site: 404.html
Only in _site/assets: main.css.map
Only in _site/assets: minima-social-icons.svg

$ diff -r -x '404.html' -x '*.map' _site /tmp/sitecopy
Only in _site/assets: minima-social-icons.svg

```

The wget/diff can be integrated into a build system. For example, as a [Makefile target](https://github.com/AppliedLogicSystems/ALSProlog/blob/bcf6245639dd0bb1cc4403a67133cb4bbdb62628/docs/GNUmakefile#L66).

---

<div class="post-metadata">

**Author:** ![george-gca](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/george-gca/32/5301_2.png) [@george-gca](https://talk.jekyllrb.com/u/george-gca)\
**Post date:** [January 19, 2025, 5:33pm UTC](https://talk.jekyllrb.com/t/how-to-check-for-un-linked-dead-files-in-site/7673/3 "2025-01-19T17:33:10Z")

</div>

Our solution to this problem was to create a GitHub action using [lycheeverse/lychee-action](https://github.com/lycheeverse/lychee-action). We have 2 versions:

- [Check for broken links](https://github.com/alshedivat/al-folio/blob/main/.github/workflows/broken-links.yml) - checks for broken links in our repository. We had to add some files to `--exclude-path` since they had a lot of links inside (like our `README.md` file), and some of these files link to external sites that might block you for checking them too often;
- [Check for broken links on site](https://github.com/alshedivat/al-folio/blob/main/.github/workflows/broken-links-site.yml) - checks for broken links in the built `_site/`. It uses `--offline` to check if all our internal links are pointing to valid files.

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [January 20, 2025, 7:30am UTC](https://talk.jekyllrb.com/t/how-to-check-for-un-linked-dead-files-in-site/7673/4 "2025-01-20T07:30:49Z")

</div>

Thank you! Will look at this ASAP.
