Conditionally create symbolic link by filesize using find exec ubuntu 10.04

Posted by jmlw on Super User See other posts from Super User or by jmlw
Published on 2012-11-06T04:57:28Z Indexed on 2012/11/06 5:06 UTC
Read the original article Hit count: 539

I have an interesting problem. I'm trying to create symbolic links in a single folder, for all files in a directory which are larger than a specified size.

For clarification, here is an example:

/Files
    /Large_Files
        /LargeFile1_symlink
        /LargeFile2_symlink
    /Folder1
        /file_a
        /file_b
    /Folder2
        /LargeFile1
    /Folder3
        /LargeFile2
        /file_c

What I have so far to try to accomplish this is:

find -size +102400 -exec ln -s $PWD/{} Large_Files/ \;

However, this find produces

./LargeFile1

So my symlink command produces

ln -s /Files/Folder2/./LargeFile1 Large_Files/

My question is, would it be possible to use the basename command to separate out only the filename so this command will work? Or does anybody have a suggestion on how to do this without writing a script, or give me an example on writing a script?

I've never done scripting before, but I do know Java, but don't want to take the time to do all this in Java.

Thank you for any help!

Edit: adding tags

© Super User or respective owner

Related posts about ubuntu

Related posts about command-line