image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old June 9th, 2003, 06:46 PM
Powermaster's Avatar
Site Supporter
 
Join Date: Dec 2001
Location: ATA Bus 0 Dev 0
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Powermaster is on a distinguished road
How to make Symbolic Links

How would one go about making a Symbolic Link?

Thanks
__________________
--Powermaster
Http://www.powermaster.cc

About me:
http://www.JasonReam.com
Reply With Quote
  #2  
Old June 9th, 2003, 10:30 PM
hazmat's Avatar
Rusher of Din
 
Join Date: Oct 2001
Location: Brooklyn, NY
Posts: 1,803
Thanks: 0
Thanked 0 Times in 0 Posts
hazmat is on a distinguished road
Here's an example. vi is in
/usr/bin/vi . You want a sym link to point to it from the same directory called vii. While in /usr/bin, you would type:

ln -s vi vii

You could specify absolute pathnames as well, so if you wanted a sym link called 'vi' in /usr/local/bin pointing to /usr/bin/vi , if you were in /usr/local/bin, you could type:

ln -s /usr/bin/vi vi


Does this make sense?
Reply With Quote
  #3  
Old June 10th, 2003, 09:52 AM
Baron in the Trees
 
Join Date: Jul 2002
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Eckhart is on a distinguished road
Yes, what 'ln' basically does is to write arg1 into a file called arg2 and flag the latter as a symbolic link.

Yet, by reading your post, I stumbled across some odds in MacOSX. I wanted to display the symbolic link as such, but not the file it is linked to. I know I was doing that somehow a whole while ago (not on MacOSX) and now I can't remember.

I tried a lot... I pentrated cat, od, file;
I messed with the "symlinks" option in tcsh. I tried to acces the file through its inode:
find ./ -inum 374355 -exec cat "{}" \;

But whatever I do, the system will always follow the symbolic link. HRRFF!

The same for directories, MacOSX will not allow to dump a directory to stdout using "od -c" for example. Whatever I do here, it keeps saying ".. is a directory".

The third question: Is any command line method known to you that flags a file as a symbolic link?

Thanks a lot!
Reply With Quote
  #4  
Old June 10th, 2003, 12:12 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,076
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
Eckhart's description of what ln does is not actually correct. The way that a symbolic link is recorded in the file system is dependent on that filesystem. You are assuming an implementation which does not correspond to what is done in HFS+.

Now on my old AT&T 3B1 I could do what you describe but that would not work on many newer file systems because the representation of the directory is more complex. For instance some file systems directly record the symbolic link in the directory structure itself.

Finally, the assumption that there is actually a "directory listing file" does not hold for all file systems. The implementation you are describing in particular does not handle accessing long absolute paths well. Each path component has to be looked up in each directory along the way by a linear search which is basically a O(n*m) operation where n is the number of path components and m is 1/2 the average number of files in a directory. In comparison OS/@'s old HPFS file system used a balanced B-tree so such a search would take O(log(total files)) time (IIRC). The latter case has much better performance characteristics but therein directories are not explicitly stored, they are built on the fly from the individual entries. (Another neat thing if you have ever used zsh doing wild-inferiors was just as cheap as globbing. That is /foo/*.c was a fast as /**/foo.c which normally under unix requires a call to find to compute.)

-Eric
__________________
Wenn ist das Nunstruck git und Slotermeyer? Ja!...
Beiherhund das Oder die Flipperwaldt gersput!
Reply With Quote
  #5  
Old June 10th, 2003, 03:03 PM
Baron in the Trees
 
Join Date: Jul 2002
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Eckhart is on a distinguished road
Quote:
Originally posted by lurk
You are assuming an implementation which does not correspond to what is done in HFS+.
So what is it then? What I see on my box, when I create a symbolic link is an autonomous file (with its own inode) with the length of exactly the source path plus a certain flag.

Quote:
For instance some file systems directly record the symbolic link in the directory structure itself.
Wow, I didn't know that. Which are these?

Quote:
therein directories are not explicitly stored, they are built on the fly from the individual entries.
See, I'm really a rookie on filesystems, that is also new to me. But this is HPFS and not HFS+ is it?

Quote:
(Another neat thing if you have ever used zsh doing wild-inferiors was just as cheap as globbing. That is /foo/*.c was a fast as /**/foo.c which normally under unix requires a call to find to compute.)
Same for tcsh and bash.

--
Is now anyone here, who can answer my actual questions? Thanks again!
Reply With Quote
  #6  
Old June 10th, 2003, 03:22 PM
Arden's Avatar
Don't drink and derive.
 
Join Date: Dec 2002
Location: San Francisco
Posts: 7,743
Thanks: 0
Thanked 0 Times in 0 Posts
Arden is on a distinguished road
The easiest way to create a symbolic link I know of is to download & install Cocktail, click on Files and the Links tab, and drag a file onto the button with the terminal alias on it.
__________________
System:
2.5 GHz MacBook Pro Core 2 Duo, 4 GB RAM, 200 GB hard drive, runs 10.5.4
1.6 GHz iMac G5, 1.5 GB RAM, 250 GB hard drive, runs 10.4.11
iPhone, 4 GB, OS X 2.0.2
Reply With Quote
  #7  
Old June 10th, 2003, 04:15 PM
lurk's Avatar
Mitä?
 
Join Date: Mar 2002
Location: Land o' skeeterz
Posts: 2,076
Thanks: 0
Thanked 0 Times in 0 Posts
lurk is on a distinguished road
Quote:
Originally posted by Eckhart
So what is it then? What I see on my box, when I create a symbolic link is an autonomous file (with its own inode) with the length of exactly the source path plus a certain flag.
I guess my point is that it was a symbolic link and you are not guaranteed anything about how it was implemented. For instance under HFS+ it may well be a file (I don't know but it certainly seems reasonable).

Quote:

Wow, I didn't know that. Which are these?
I remember that from my OS class of many many winters ago, I can't say that I remember the exact file system. The basic idea was that the target of the symbolic link was stored in filename slot of a directory entry and then had a bit set flagging it as "not a real file name". A symbolic link then did not index into the set of inodes but rather the directory index which contained the target.

The real moral of this is that with all the different implementations of this stuff over the ages for almost any cockamamy way you can come up with doing something somebody did it.

Quote:

See, I'm really a rookie on filesystems, that is also new to me. But this is HPFS and not HFS+ is it?
Yes it is HPFS and I think that is part of the reason that there were never any Linux drivers able to write HPFS. It was just too different, that said I believe that NTFS has inherited some of these features and is in a similar situation of partial support.

I honestly just don't know what HFS+ does I haven't had reason to look it up.
Quote:

Same for tcsh and bash.
Nope you misunderstood the ** that will match any number of arbitrarily nested directories. So /foo/**/bar.c would match /foo/baz/quuz/zot/bar.c which is not possible in bash or tsch. In those cases you have to use find to grovel over the directory for you. Another point is that this is very sow by comparison and on something like HPFS a wild inferiors match like above would be super fast.

Quote:

Is now anyone here, who can answer my actual questions? Thanks again!
Well I thought I did in an obtuse sort of way which is to say you cannot in general do what you are trying to do. I also know this from experience in trying to use a combination of dd and fsck to delete an undeletable file. Nothing says that you can cat a directory or a symlink on any filesystem on any given unix. Now it may work on some implementations like my old 3b1 but it is just an accident really.

On a side note if I can write a directory via cat like you could in the old old days that also means that I can own the box. All I have to do is copy a shell into a directory, make it setuid me and then edit the directory file to change that little uid to root's. Now I am root and on my merry way.

Note to moderators that is not really a description of how to hack a box as it would not work on any modern computer.

So what are you really trying to do? Just make a symbolic link, that was already answered. Convert a normal file into a symlink using its contents as a target via some backdoor way?

-Eric
Reply With Quote
  #8  
Old June 11th, 2003, 04:26 AM
Baron in the Trees
 
Join Date: Jul 2002
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Eckhart is on a distinguished road
Without bringing it up at large, my questions were:

1. How do I make the system (in whatsoever way - and regardless to all the implementations over the ages it is not working on) to stop following symbolic links?
2. Is any "hack" known to somebody how I can dump a directory to stdout? As it was once possible -and not only one system- with "od -c".

Ok, and most about your point was basically that we cannot find a patent remedy due to all these different implementations and filesystems... -- which is an euphemism for "NO" to both questions.

Well, anyways I didn't want to bother, if the answer doesn't come handy, I did not want to start a major thread. It was just the idea that somebody would know.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Apache, symbolic links and permissions Kinniken Unix & X11 2 August 31st, 2003 08:10 AM
symbolic links via web macidiot Design & Media 0 January 29th, 2003 06:05 PM
How to compile stuff fintler Unix & X11 1 August 28th, 2002 08:57 AM
Apache config Q / symbolic links Q andypeter Mac OS X System & Mac Software 2 April 18th, 2001 02:33 PM


All times are GMT -5. The time now is 07:01 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.