1

I want to make symlinks for image files in a directory in the server. Currently I'm doing it by executing this command using php function exec():

ln -sf path/to/source path/to/symlink

Both file names are the same.

And it's working greatly. In the next step I want to make symlinks for other sizes of that particular image which are stored alongside the original image. I searched and find this link: Execute a command on find results which explains to use this format:

find ... -execdir rm {} \;

Now the furthest I got is to list files (full path) using find with the proper regex. But I have no idea how to use this output and link each file to the exact name in target directory.

P.S.: I only have access to the original image and its path.

EDIT:

As I mentioned I only have access to the image path and its filename. And I don't know how many sizes of the image is available. So I want to combine find and ln so that all image sizes of the original image file get linked to source files. For example: I get the path to an original image like this:

path/to/file/microlancer.png

until now I was executing this command:

ln -sf path/to/file/microlancer.png path/to/symlink/microlancer.png

with an execution of a find I obtain these files:

path/to/file/microlancer-260x185.png
path/to/file/microlancer-120x120.png
path/to/file/microlancer-705x321.png
path/to/file/microlancer-450x223.png
path/to/file/microlancer-150x150.png
path/to/file/microlancer-495x350.png
path/to/file/microlancer-300x149.png
path/to/file/microlancer-705x350.png
path/to/file/microlancer-450x350.png
path/to/file/microlancer-180x180.png
path/to/file/microlancer-36x36.png

And I need a symlink in path/to/symlink/ for each above file.

php is not a matter here. I just need the command in linux. I only mentioned php to clarify that I don't have access to all files.

4
  • 4
    It's a little unclear what you're wanting to achieve. Would it be possible to post more detail, including, perhaps, the relevant part of your existing php exec() script ? Commented Sep 8, 2018 at 10:16
  • 1
    Also, what is the plan for the symlink path? For each found file, how would you determine what the associated symlink is? Please edit your question to include this information. Commented Sep 8, 2018 at 10:52
  • 1
    @steve There is a danger in it, his question may be closed as offtopic as a programming question :-( Commented Sep 8, 2018 at 10:52
  • Would you like to create symbolic link for all the lines in the list that you had provided, instead of applying your command ln -sf path/to/file/microlancer.png path/to/symlink/microlancer.png on the images one by one? Commented Sep 8, 2018 at 11:51

2 Answers 2

1
find /path/to/file -name '*.png' -exec ln -s '{}' /path/to/symlink ';'
0
0
cd /path/to/file
find `pwd` -name "*.png" | xargs -I {} ln -s {} path/to/symlink/

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.