Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - chklnks


chklnks - locates and optionally removes broken symbolic links.


chklnks [[[ -a ]| [ <directory> ... ]] [ -d ] [ -h <hostid|> ] [ -r ] [ -v ]]| [ -V ]


chklnks is a Bourne shell script which should work equally well on all versions of UNIX and Linux.


The script chklnks, runs " find " to locate files which are symbolic links where the target file is missing

By default the path and file name of any broken link found are echoed to to " standard out ".

The script is mostly usefully invoked by " cron " to a regular weekly schedule.


-a    Check all the local read write filesystems on the target host

-d    Set the script to debug mode.

-h <hostname>
Run the script on a remote host.

-r    Broken symbolic links are removed.

-v    Set the operation mode of the script to verbose. In verbose mode chklnks will report any broken symbolic links and their removal to standard out .

<directory> If given on the command line <directory> is the starting point for the find. Multiple space separated directories may be listed on the command line.

If no <directory> is nominated on the command line the current directory is is used as the starting point.



From the current directory search recursively for broken symbolic links and report any found to /fIstandard out/fR.

chklnks -v -r /src/merlin/usr/local/web 

Starting from /src/merlin/usr/local/web do a recursive search for broken symbolic links and remove them. Report each file deleted to standard out.




The script has no input error checking. I'm a bit worried about what happens if filenames with white space in them are found. These names will be passed to rm as multiple file names which could potentially match real files!


chkdf, chkftpd, chkfw, clean.


Clifford W Fulford of City Linux.
Offering systems management and support for Linux, Windows and Apple environments. Contact or +44 (0)709 229 5385.

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.