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.


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:


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:


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
    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 ?
    – steve
    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.
    – Sparhawk
    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 :-(
    – peterh
    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?
    – user88036
    Sep 8, 2018 at 11:51

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .