Skip to content
Advertisement

link files within directory, with simple command similar to cp

Where my question originated:

  • When running cp source/files.all destination/, all the files within source will now also exist in destination

Question:

  • What if I didn’t want to duplicate the data from source into destination, but simply link them (with absolute path). Usually, I would run something like:

    for f in $(ls source/); do ln -s $(pwd)/${f} $(pwd)/destination; done

    Is there a simple command/tool that I can use (e.g. ln -a source/files.all destination/) which would create a softlink to all files in a directory, while automatically adding the absolute path as prefix. ln -r is close to what I need, but the absolute path, not the relative one?

Advertisement

Answer

So I eventually sort of found a simple way to do this:

Simply run ln -s $(pwd -P)/source/* destination/

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement