From owner-freebsd-questions@FreeBSD.ORG Wed Jun 28 00:07:18 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CF95F16A4AB for ; Wed, 28 Jun 2006 00:07:18 +0000 (UTC) (envelope-from paul+fbsd@it.ca) Received: from mail2.dm.egate.net (mail2.dm.egate.net [216.235.1.136]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1A34345541 for ; Tue, 27 Jun 2006 21:30:23 +0000 (GMT) (envelope-from paul+fbsd@it.ca) Received: from mail.it.ca (root@[216.235.7.67]) by mail2.dm.egate.net (8.12.11/8.12.10) with ESMTP id k5RLUMto001160; Tue, 27 Jun 2006 17:30:22 -0400 (EDT) (envelope-from paul+fbsd@it.ca) Received: from mail.it.ca (paul@mail [216.235.7.67]) by mail.it.ca (8.13.3/8.13.3) with ESMTP id k5RLTXt5025524; Tue, 27 Jun 2006 17:29:33 -0400 (EDT) (envelope-from paul+fbsd@it.ca) Received: (from paul@localhost) by mail.it.ca (8.13.3/8.13.3/Submit) id k5RLTXDm025523; Tue, 27 Jun 2006 17:29:33 -0400 (EDT) (envelope-from paul+fbsd@it.ca) X-Authentication-Warning: mail.it.ca: paul set sender to paul+fbsd@it.ca using -f Date: Tue, 27 Jun 2006 17:29:33 -0400 From: Paul Chvostek To: sara lidgey Message-ID: <20060627212933.GA23336@it.ca> References: <20060627181422.6917.qmail@web35702.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060627181422.6917.qmail@web35702.mail.mud.yahoo.com> User-Agent: Mutt/1.5.11 Cc: freebsd-questions@freebsd.org Subject: Re: multiple links with single ln command X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jun 2006 00:07:19 -0000 Hiya. On Tue, Jun 27, 2006 at 02:14:22PM -0400, sara lidgey wrote: > > I've read the man page for ln but can't find a way to do this. I want to create multiple links to a single directory with one command. Consider the following example. I have a directory structure like this: > test/a/ > test/b/ > test/c/ > I want to create a symbolic link called "clink" in test/a/ and test/b/ which points to test/c/ > > The only way I know to do this is with two commands: > ln -s test/c test/a/clink > ln -s test/c test/b/clink > > Can it be done with a single command? No. Well, it depends on what you consider a single command. :) Consider that your command line uses fileglob expansion to determine the full command line *before* the command is run. The notation you're looking at is this: ln [-fhinsv] source_file ... target_dir which means the `ln` command takes a left-hand-side (the source, possibly multiple sources) and a right-hand-side (the target). But you're asking to go the other way around, with a single source being created in multiple targets. If you have ALOT of these links to make, or need to do this on an regular basis, I suggest making a small script that does what you want; perhaps something like this: #!/bin/sh if [ $# -lt 2 ]; then echo "Usage: altln source_file target_dir ... exit 1 fi source_file="$1"; shift for target_dir in $*; do ln -svi "$source_file" "$target_dir" done ... which you can run with a command line like: # ls -F test/ a/ b/ c/ # altln ../c test/a test/b # ls -l test/*/* lrwxr-xr-x 1 root wheel 4 Jun 27 17:28 test/a/c -> ../c lrwxr-xr-x 1 root wheel 4 Jun 27 17:28 test/b/c -> ../c # (Bear in mind that the symbolic link you create will be evaluated relative to ITS location, not your cwd when you create the link.) -- Paul Chvostek it.canada http://www.it.ca/