Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted
$ 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


share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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