help with symlinks
Ok, so i've got a directory with a large number of randomly-named subdirectories inside it, and i would like to symlink the subdirectories and their respective files to another folder.
i'm not very experienced with soft links, is it possible to have it create the folders named the same as they are in the original folder and then symlink the files into them so the program i use to scrape will recognise the file names? Sorry if i'm not particularly clear in what i want. For example: originaldir/abcdef/file.txt symlinkeddir/abcdef/file.txt is there any easy way to automate creating folders named the same and then symlinking the files into it? |
What you describe doesn't make much sense.
What are you trying to do, precisely? As in, what task is this symlink approach supposed to help with? EDIT: just as a follow-up, symlinking will default to the same file/directory name as the target if no alternate name is supplied. For instance: Code:
ln -s /path/to/fileA /alternate/path/ EDIT2: For a directory containing one level of subdirectories and files within those subdirectories, this shell script will "mirror" the directory structure and populate the subdirectories with symlinks to the original files. You would runn it with the source directory (the one you wish to mirror) as the first argument and the destination directory as the second argument. The script will not actually do anything at the moment other than print the commands it would execute. To "turn it on," once you are satisfied that it's doing what you need, delete all the occurrences of the red echo in the script, save, and re-run. Code:
#!/bin/bash |
Perhaps ... (dunno...) ... this notion will help.
"A symlink is a tiny little file with the name of a directory-path in it." That's it... that's all. When you use a directory-path that, the shell realizes, contains a "symlink" in it, the shell reads the contents of "that tiny little file" and substitutes the directory-path therein contained into the "actual" search path that it subsequently tries to use. After making that textual substitution, the shell then attempts to find the directory-path so named. (A hard link is slightly more counter-intuitive: in this case, the "tiny little file" contains an iNode number. Blah, blah blah... pay no attention to the little man behind the curtain...) |
Ok, so I probably wasn't as clear as I should have been, having read the replies has made me re-think how to say what I'm trying to achieve. My overall goal was to have a script that you pointed at a directory, then it would go list all the subdirectories and then re-create them in a destination directory, basically creating a copy. It would then create a symlink to the files within the original subdirectories and place them in the newly created directories. Does that make sense? Sorry if it's a bit confusing to read, couldn't think of another way to describe it.
|
Why not just symlink the parent dir?
|
If I symlink the parent dir, does it recursively create symlinks for all files in the subdirectories? I'll be using a program to scrape the symlinked dirs and the file structure needs to stay in place. I've no idea with using symlinks.
|
A symlink is just a "signpost". If you create /link as a symlink to /my_dir then opening /link/a/b/c will actually open /my_dir/a/b/c
There are very few exceptions to this. I once found a Perl script that did not follow the above convention. |
Ok, so here's an extension on my previous post. Once the scraper had scraped all the folders, it would then deposit artwork in the new dirs. Now, where would the artwork files end up? in my new directories, or the ones they linked to?
|
OK ... you'll need to create a directory tree that mimics the original, and then
individually (via script) symlink the files to the targets, then do your "scraping"... If you THEN place a new / replacement file in the target structure the new file will actually live there. What's the over-all task that you're trying to accomplish, what does the scraping do? Cheers, Tink |
Quote:
|
Slightly off at a tangent, but I've been doing some testing and i think i've sorted how i'm going to recreate all the directories (but not the files), using the following command:
Quote:
edit: answering my own question, it does do the trick nicely! now how on earth do i write a script to loop through each folder in the source dir and to then create the symlinks in the newly created destination dirs? in case anyone needs an answer to this, i have now solved the problem, the following should do the trick: Quote:
|
All times are GMT -5. The time now is 11:29 AM. |