Not sure if this is the right spot to post this (if it isn't, sorry)

Due to some restrictions (and preferences) I'm finding myself at a dead end. Machine is running ProxmoxVE (Debian/QEMU based hypervisor).

The issue is that Proxmox doesn't check inside sub-directories for .iso files (needed for deploying VMs) and I can't modify the file repository's structure.

I'm trying to figure out how to automatically generate symlinks based on file extension. My idea is to have one directory with dynamic mappings to every .iso file that way I can add/remove them easily.

Example file structure:

Folder A
 -Folder B
   -ISO A
 -Folder C
   -ISO B
   -ISO C

Required file structure:

Folder A

I can run scripts as needed but don't possess the knowledge to write said script.

Any help would be greatly appreciated!

Edit 1: I have another folder I'm planning on having all the symlinks stored in

  • You cant do exactly as you asked, you can either have a new folder with the flattened structure, or (filesystem allowing) you can have a symlink in Folder A and keep the existing flattened structure for it as well. Can you change Folder A in your second code snippet "Folder A" to "NewFolderA"? – davidgo Sep 19 '18 at 21:46
  • I forgot to add I have another directory I'd like to add all the symlinks in. I tested it with one, but want to have it dynamically update. – CelluloidRacer2 Sep 19 '18 at 21:47

This can be done as a one-liner as follows:

find "/path/to/FolderA" -type f -name "*iso" -exec  ln -s {} /path/to/symlinkfiles \;

To turn this into a script


find "$SOURCEFILES" -type f -name "*.iso -exec ln -s {} $FLATTENEDFILEDIR \;

These work as follows - the find command looks for files in a given location, the "type f" means it only looks for files, so symlinks and subdirectories are not executed (but the directories are looked into for files), the *.iso expects that that is the file extension.

The second part (after -exec) is executed for each file, and creates the symlink.

You might want to throw in something like "rm -r $FLATTENEDFILESDIR/*" at the top of this script if its permissible to remove existing symlinks, so you don't land up with dead ones - BUT IT IS VITAL YOU HAVE SET FLATTENEDFILESDIR correctly first, as failure to do this could wipe most of your system!

  • You could trigger this command or script to run periodically from cron to automate updates. – davidgo Sep 19 '18 at 23:43
  • Much thanks! Just to confirm, running rm -r removes the symlink but not the actual file right? – CelluloidRacer2 Sep 20 '18 at 1:14
  • rm -r recursively removes everything matching the specified parameter, including symlinks and regular files - thus it will remove everything in the FLATTENEDFILESDIR. For the sake of clarity it will remove the symlinks in that directory, but it will not remove the files which the symlinks point to, provided that they are in a different directory. – davidgo Sep 20 '18 at 4:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.