I'm trying to create multiple symbolic links using wildcard, here the example:
$ ls -R .: TXT a b ./TXT: ./a: a.txt ./b: b.txt There is a "parent directoory" containing various subdirs: a, b, TXT. In "a" and "b" there are various text files (a.txt, b.txt in the above example).
I want to create "relative" symbolic links to each ".txt" files whitin the "TXT" subdir. But:
- without using "find"
- without "cd" in TXT directory
In other words I want to know why a command like the following doesn't work:
ln -s ../*/*txt TXT/ With a previus "cd TXT" it works:
cd TXT ln -s ../*/*txt . I think the issue appears due to bash expansion of "*" and "../", bash is not able to expand "../*/*.txt" because those files actually don't exist, so "ln" cannot create the desired links: it creates links to txt files of "one level up" dirs relative to the current workdir. It "cd" to ".." and considers all dirs at this level, looking for the ".txt" files within these.
Maybe "the rule" could be symlink TARGET has to:
- point at the same time at real existing files (otherwise bash can't expand ".." or "*" in the right way)
- and it has to be relative to the DIRECTORY that will contain the link
Could you confirm and explain what exactly is the problem and possible solutions?
PS. Using "find", a command like the following seems to work:
find ./ -path ./TXT -prune -o -iname "*.txt" -type f -exec ln -s ."{}" -t TXT/ \; Note that even in this case I have to use a "non existing" path:
."{}" But the -exec command just expands "{}" which is "./a/a.txt" and "./b/b.txt", so "ln" can build the right path relative to TXT destdir thanks to the prefixed dot ".".