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:

/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

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-4.2.0.2_p.a -> /usr/lib/ghc-6.12.3/base-4.2.0.2/libHSbase-4.2.0.2_p.a
lrwxrwxrwx 1 jaroslav jaroslav 56 Nov  9 02:55 libHSCabal-1.8.0.6_p.a -> /usr/lib/ghc-6.12.3/Cabal-1.8.0.6/libHSCabal-1.8.0.6_p.a
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

links

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 .