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:


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

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

However, this find produces


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

$ find /usr/lib -size +20M  -size -25M -exec sh -c 'ln -s "{}" /tmp/huge/`basename {}`' \;
find: `/usr/lib/mozilla': Permission denied
geee: /
$ ll /tmp/huge/
total 0
lrwxrwxrwx 1 jaroslav jaroslav 45 Nov  9 02:55 HSghc-6.12.3.o -> /usr/lib/ghc-6.12.3/ghc-6.12.3/HSghc-6.12.3.o
lrwxrwxrwx 1 jaroslav jaroslav 54 Nov  9 02:55 libHSbase- -> /usr/lib/ghc-6.12.3/base-
lrwxrwxrwx 1 jaroslav jaroslav 56 Nov  9 02:55 libHSCabal- -> /usr/lib/ghc-6.12.3/Cabal-
lrwxrwxrwx 1 jaroslav jaroslav 59 Nov  9 02:55 libHSghc-6.12.3-ghc6.12.3.so -> /usr/lib/ghc-6.12.3/ghc-6.12.3/libHSghc-6.12.3-ghc6.12.3.so
lrwxrwxrwx 1 jaroslav jaroslav 33 Nov  9 02:55 libQtWebKit.so.4.9.2 -> /usr/lib/qt4/libQtWebKit.so.4.9.2
lrwxrwxrwx 1 jaroslav jaroslav 26 Nov  9 02:55 libxul.so -> /usr/lib/firefox/libxul.so
lrwxrwxrwx 1 jaroslav jaroslav 20 Nov  9 02:55 opera -> /usr/lib/opera/opera


  • Thank you so much! I thought I was close with my command. I did have a problem with the above though, I needed to add the -a switch to basename, otherwise it randomly cut off the file name (file names had spaces). @Ярослав Рахматуллин – jmlw Nov 9 '12 at 3:31
  • Use quotes around arguments with spaces. – Ярослав Рахматуллин Nov 9 '12 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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