[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Linking Recursively



On Thu, Nov 30, 2000 at 01:17:06PM -0600, Robert Guthrie wrote:
> On Thursday 30 November 2000 12:51, Miquel van Smoorenburg wrote:
> 
> > This is Unix, so you use several tools together to accomplish
> > whatever you want:
> >
> > $ mkdir collapsed
> > $ cd collapsed
> > $ find /original/path -print0 | xargs -0 -n 1 ln -s
> >
> > [untested ofcourse!]
> >
> > Mike.
> 
> actually, 
> 
> find /original/path -type f -exec ln -s {} . \;
> 
> will do the same thing as your find + xargs program.
> "find" was a hard untility to wrap my brain around, but I evenutally got it, 
> and now I use it for all sorts of quick one-liners like this.
> Broken down, this is what the above command does (for the uninitiated):
> 
> find /original/path : starting in the directory /original/path, search for 
> all files under that directory.
> 
> -type f : an argument to find which narrows down the search to 
> non-directories and non-symbolic links (most any type of file).  Normally, it 
> will return directories and symbolic links as well as other types of files.
> 
> -exec ln -s {} . \;    This one is the hard one.  -exec executes the rest of 
> the line (up to the \;), using each file that the find command returns as 
> that commands argument.  the {}'s are like a variable that represent that 
> filename.   So if find /original/path -type f    returns 
> /original/path/somedir/myfile.txt, the command to be executed would be 
> ln -s /original/path/somedir/myfile.txt  .
> 
> Finally, note the "." at the end of the ln command.  That tells ln to make a 
> link of the first argument in the current working directory (where you were 
> when you executed the find command).  It will use the same file name as the 
> original file.
> 
> The ";" is to tell find where the argument to -exec finishes.  You can add 
> other command line arguments after that.  The reason for the "\" before it is 
> that your shell will look at the semi-colon and think that it's for 
> separating two commands on the same line (try this to see what the shell does 
> with ;'s : cd /etc  ; ls).  The shell always does this with semi-colons 
> before executing a command, so you have to hide it from the shell by 
> "escaping" it.

nice job!

> Man.  I think I should go do some of what my employer is paying me for now 
> instead of providing unsolicited "find" tutorials.  Read the find man page 
> for more usefull options.

on the other hand, if you could flesh this out a bit, we'd
love to include it at our newbieDoc site to that next week's
newbie won't have to clutter debian-user with a "how does 'find'
work" question... ?

can you help us? -or them?

-- 
will@serensoft.com    ***    http://www.dontUthink.com/

volunteer to document your Debian experience for next week's
newbies -- http://www.eGroups.com/messages/newbieDoc



Reply to: