something like this might work for you but you can encounter errors creating links if it already exists...
Code:
find /home/username/tld/ -type f -iname \*.jpg -exec dirname {} \; | xargs -I{} ln -s {} ~/tmp/
also if you had multiple folders, like in your example except something along the lines of:
Code:
- Folder 1
- Folder 1a
1.jpg
2.jpg
- Folder 2a
5.jpg
6.jpg
- Folder 2
- Folder 2a
3.jpg
4.jpg
- Folder 3
- Folder 3a
index.html
- Folder 1a
7.jpg
you would have no way of creating multiple links of the same name in the destination directory
i'd probably do something along the lines of calling a script from find's -exec option and work from there to create the link named off of some hash of the path...
Code:
find /home/username/tld/ -type f -iname \*.jpg -exec /home/username/bin/linkit.sh {} \;
linkit.sh
Code:
#!/bin/bash
#
# create links in ~/tmp/ to directories with .jpg files
DSTDIR="/home/username/tmp/"
IN="$1"
DIRNAME=$(dirname ${IN})
SHANAME=$(echo ${DIRNAME} | sha1sum | cut -d" " -f1)
LINKNAME="$(DSTDIR}/${SHANAME}"
if [ ! -d ${DSTDIR} ]; then
mkdir ${DSTDIR}
fi
if [ ! -h ${LINKNAME} ]
ln -s ${DIRNAME} ${LINKNAME}
fi
wrote this on the fly, so use at own risk ;-)
also, recommend calling all binaries from absolute path rather than relative (or at least defining a sane PATH variable in the script)