Date: Tue, 27 Jun 2006 17:29:33 -0400 From: Paul Chvostek <paul+fbsd@it.ca> To: sara lidgey <slidgey@yahoo.ca> Cc: freebsd-questions@freebsd.org Subject: Re: multiple links with single ln command Message-ID: <20060627212933.GA23336@it.ca> In-Reply-To: <20060627181422.6917.qmail@web35702.mail.mud.yahoo.com> References: <20060627181422.6917.qmail@web35702.mail.mud.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <paul@it.ca> it.canada http://www.it.ca/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060627212933.GA23336>