Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 -> /usr/lib/ghc-6.12.3/ghc-6.12.3/
lrwxrwxrwx 1 jaroslav jaroslav 33 Nov  9 02:55 -> /usr/lib/qt4/
lrwxrwxrwx 1 jaroslav jaroslav 26 Nov  9 02:55 -> /usr/lib/firefox/
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .