1

How can I write a script that will move all .png .svg .gif files from /home/eric/Desktop to /usr/share/icons?

3 Answers 3

3

bash can handle this easily:

mv /home/eric/Desktop/*.{png,svg,gif} /usr/share/icons

Use sudo mv ... if you don't have permission to write into /usr/share/icons.

3
  • There ya go, pushed you over 3k.
    – slm
    Mar 26, 2014 at 1:24
  • I shall only use my powers for evil... Mar 26, 2014 at 2:42
  • Needs a maniacal laugh at the end of that comment, ala Dr. Evil from Austin Powers or something 8-)
    – slm
    Mar 26, 2014 at 2:43
0

As follows

#!/bin/sh

gksu mv /home/eric/Desktop/*.png /usr/share/icons & mv /home/eric/Desktop/*.svg /usr/share/icons & mv /home/eric/Desktop/*.gif /usr/share/icons & exit

I'm not a bash expert - but this should work. if it doesn't there is no warranty with my answer :P

8
  • works with some modification
    – era878
    Mar 15, 2011 at 0:15
  • 1
    That's an sh script, not a bash script, and there's no point in running the mvs in parallel. I'd make a bash-script that does shopt -s extglob and then mv ~eric/Desktop/*.@(png|svg|gif) /usr/share/icons/
    – geirha
    Mar 15, 2011 at 7:15
  • told you I'm no expert :P
    – RolandiXor
    Mar 15, 2011 at 13:29
  • i'd use 'sudo' instead of 'gksu' in a shell script. im no expert either.
    – djangofan
    Mar 22, 2011 at 21:41
  • sudo is good, but gksu is safer, and graphical
    – RolandiXor
    Mar 23, 2011 at 1:01
0

Why not use find? This worked for me:

find ./  -maxdepth 1 \( -iname "*.png" -o -iname "*.gif" -o -iname "*.svg" \) -ok cp {} /tmp/ \;

You want to mv not cp, and your destination is /usr/share/icons not /tmp but you can run this from the command line or a shell script.

-iname is case insensitive, -name would be case sensitive. Tweak the -maxdepth to your liking, and/or pull of the -ok clause to just see what it is coming up with.

You must log in to answer this question.

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