Re: multiple links with single ln command
On 2006-06-27 14:14, sara lidgey [EMAIL PROTECTED] wrote: Hi All, 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? I don't think so. The closest you can come to ``a single command'' would be a loop: $ for dirname in a b ; do ln -s test/c test/$dirname/clink ; done ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: multiple links with single ln command
Thanks for all the ideas. They are very helpful. -S Brian O'Shea [EMAIL PROTECTED] wrote: It can be done with a shell for-loop: $ mkdir a b c $ for dir in a b ; do (cd $dir ; ln -s ../c clink) ; done But this is technically not a single command, and it assumes that you are using the Bourne Shell (/bin/sh) or a Bourne-compatible shell (ksh, zsh, bash, etc.). If you are a csh or tcsh user, may God help you. (I mean look up the syntax in the appropriate man page.) -brian --- sara lidgey wrote: Hi All, 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? thanks. sorry if this is a no-brainer, S __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] - Make free worldwide PC-to-PC calls. Try the new Yahoo! Canada Messenger with Voice ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
multiple links with single ln command
Hi All, 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? thanks. sorry if this is a no-brainer, S - Now you can have a huge leap forward in email: get the new Yahoo! Mail. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: multiple links with single ln command
Unfortunately, it is impossible with the current syntax of the ln command. It does allow you to specify multiple sources as arguments though, with a final argument naming a target directory in which to create the links to the source files. For example: $ mkdir test $ mkdir test/a $ mkdir test/b $ mkdir test/c $ mkdir links $ cd ./links $ ln -s ../test/* . $ ls -l lrwxr-xr-x 1 boshea boshea 9 Jun 27 15:50 a - ../test/a lrwxr-xr-x 1 boshea boshea 9 Jun 27 15:50 b - ../test/b lrwxr-xr-x 1 boshea boshea 9 Jun 27 15:50 c - ../test/c However, this is not exactly what you are trying to do in your example; you are trying to create multiple target links with the same name in different directories. Unfortunately, because the ln command's syntax allows you to specify multiple source files, it would be ambiguous to try to make it also allow you to specify multiple targets. Hope that helps. -brian --- sara lidgey [EMAIL PROTECTED] wrote: Hi All, 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? thanks. sorry if this is a no-brainer, S - Now you can have a huge leap forward in email: get the new Yahoo! Mail. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: multiple links with single ln command
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 [EMAIL PROTECTED] it.canadahttp://www.it.ca/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: multiple links with single ln command
It can be done with a shell for-loop: $ mkdir a b c $ for dir in a b ; do (cd $dir ; ln -s ../c clink) ; done But this is technically not a single command, and it assumes that you are using the Bourne Shell (/bin/sh) or a Bourne-compatible shell (ksh, zsh, bash, etc.). If you are a csh or tcsh user, may God help you. (I mean look up the syntax in the appropriate man page.) -brian --- sara lidgey [EMAIL PROTECTED] wrote: Hi All, 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? thanks. sorry if this is a no-brainer, S __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]