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.

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.

-- 
Did you know that if you play a Windows 2000 cd backwards, you 
will hear the voice of Satan?

That's nothing!  If you play it forward, it'll install Windows 2000.

Reply via email to