Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not a server guru (unfortunately) but have a decent knowledge of linux & bsd. I'm trying to symlink multiple instances of HLDS (game server) but need to exclude certain folders & config files to achieve this properly. I need to do it this way as HLDS loads many mods automatically, and putting an exception to disable the mods doesnt work for all of them.

so basically i want:

/home/user/hlds-install (the base install)

and then be able to manually put any configs/mods ive excluded into the server dir's so that each server can be configured individually.

Can anyone tell me how to do this, perhaps some sort of bash script so that I can just change the targets to run it each time i want to create a new one. I have quite a number to make so doing the whole thing manually for each one definately isn't an option and im all for working smarter, not harder!

Thanks :)

share|improve this question

I assume you really mean "symlink everything inside the folder"...

Conceptually, you want something like:

for each file in base folder not in exclude list
    create symlink in target folder pointing back to base folder

bash logic to achieve this goes something like

#! /bin/bash

exclude=( "foo.conf" "bar.conf" )

for file in *; do
    for (( index = 0; index < ${#exclude[@]}; index++ )); do
        if [[ ${file} != ${exclude[${index}]} ]]; then
            ln -s ${file} ${target}/${file}

Assuming you don't know already, the Advanced Bash-Scripting Guide should give you enough to work out what globbing you want (perhaps find) and how to convert that to a function (perhaps a recursive one).

share|improve this answer
thanks :) sorry if I confused the wording. so yeah I do want to make it recursive, to copy the whole folder structure for the base installation - and then just exclude certain folders or files from being linked. will check out that scripting guide! – Jarrod White Jul 30 '10 at 2:36

You could (ab)use xstow. This program is designed to populate a forest of symbolic links, which is close to what you want. It doesn't have an option to exclude some files, but you can hack it, sort of. For each server:

  1. Create files that you want to exclude from this server. The contents don't matter, they just have to be easy to tell afterwards, so we'll make them all hard links to one particular file.
  2. (You don't mention this in your requirements but it's easy to fit in.) Symlink files that must have a server-specific contents from a hierarchy that contains only those files.
  3. Symlink files from the base install. Skip over any file that's already present.
  4. Remove the files we in fact wanted to exclude from this server.
cd .../targets/server1
touch .exclude
for x in files to exclude; do mkdir -p "$(dirname "$x")"; ln .exclude "$x"; done
xstow -d .../sources -t . server1-specific-files
xstow -f -d .../sources -t . base-install
find -samefile .exclude -exec rm {} +
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.