Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

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

share|improve this answer
    
works with some modification –  era878 Mar 15 '11 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 '11 at 7:15
    
told you I'm no expert :P –  RolandiXor Mar 15 '11 at 13:29
    
i'd use 'sudo' instead of 'gksu' in a shell script. im no expert either. –  djangofan Mar 22 '11 at 21:41
    
sudo is good, but gksu is safer, and graphical –  RolandiXor Mar 23 '11 at 1:01
show 3 more comments

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.

share|improve this answer
    
There ya go, pushed you over 3k. –  slm Mar 26 at 1:24
    
I shall only use my powers for evil... –  glenn jackman Mar 26 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 at 2:43
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.