Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
Needing help to make a fully functional Bash script [SOLVED]
Needing help to make a fully functional Bash script [SOLVED]
Hello!
I can't seem to make a working Bash script to do the following:
1. I have a folder where multiple ZIP files are stored, all these ZIP files contain many subdirectories, so using this command will just make a big mess:
for i in `find . -name "*.zip"`; do unzip -d `dirname $i` $i;done;
What I want would be to unzip each folder into a directory created with mkdir with the ZIP filename as the directory name (without the ending .zip extension!)
2. Convert all PNG images into JPG in a directory with lots lots of subdirectories containing PNG images and finally removing all PNG images.
3. List all directories in a folder and adding "_old" to the end of the directory name. (I need this to separate older and newer projects)
------------------------------
I have tried many times, but with no success. I know that someone might think that I'm a Pr0-Linux user, but I'm just a normal user with nearly no knowledge about basic commands used in Linux.
I appreciate it if someone could help me to make a Bash script to make my life easier; I am sure others will also benefit from it. Thanks!
I can't seem to make a working Bash script to do the following:
1. I have a folder where multiple ZIP files are stored, all these ZIP files contain many subdirectories, so using this command will just make a big mess:
for i in `find . -name "*.zip"`; do unzip -d `dirname $i` $i;done;
What I want would be to unzip each folder into a directory created with mkdir with the ZIP filename as the directory name (without the ending .zip extension!)
2. Convert all PNG images into JPG in a directory with lots lots of subdirectories containing PNG images and finally removing all PNG images.
3. List all directories in a folder and adding "_old" to the end of the directory name. (I need this to separate older and newer projects)
------------------------------
I have tried many times, but with no success. I know that someone might think that I'm a Pr0-Linux user, but I'm just a normal user with nearly no knowledge about basic commands used in Linux.
I appreciate it if someone could help me to make a Bash script to make my life easier; I am sure others will also benefit from it. Thanks!
Last edited by thamarok on 2007-01-28 18:24, edited 1 time in total.
rename 'y/A-Z/a-z/' *; for i in $(find -iname '*.zip'); do mkdir `basename $i .zip`; unzip -d `baseename $i .zip` $i; done
EDIT:
forgot about the png and old stuff, but I'm going to eat now, I'm sure you can add those things yourself, and if not you're just a forum away from help (:
EDIT:
forgot about the png and old stuff, but I'm going to eat now, I'm sure you can add those things yourself, and if not you're just a forum away from help (:
Eagles may soar, but weasels don't get sucked into jet engines...
Thanks Grifter!
Your script works well, but after editing a small typo:
rename 'y/A-Z/a-z/' *; for i in $(find -iname '*.zip'); do mkdir `basename $i .zip`; unzip -d `basename $i .zip` $i; done
You had "basename" written as "baseename"
Now if someone could help me to have a script for the 2nd and 3rd operations ..
Your script works well, but after editing a small typo:
rename 'y/A-Z/a-z/' *; for i in $(find -iname '*.zip'); do mkdir `basename $i .zip`; unzip -d `basename $i .zip` $i; done
You had "basename" written as "baseename"
Now if someone could help me to have a script for the 2nd and 3rd operations ..
for the latter things look into the looping capabilities of bash script
for example if we look at http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html we find the example
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
should be pretty easy to tweak that to only list directries and rename each one.
for example if we look at http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html we find the example
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
should be pretty easy to tweak that to only list directries and rename each one.
How can I tweak ls to list only directories??plugwash wrote:for the latter things look into the looping capabilities of bash script
for example if we look at http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html we find the example
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
should be pretty easy to tweak that to only list directries and rename each one.
- runningwithscissors
- Posts: 3
- Joined: 2007-01-26 14:18
thamarok wrote:How can I tweak ls to list only directories??
Code: Select all
$ for i in `ls`; do if [ -d ${i} ]; then echo ${i}; fi; done;
Happiness, is not being afraid. -- Roy Keane (supposedly)
for i in $( find -iname '*jpg'); do mogrify -format png $i; done
now if you wanted to remove it, after the mogrify one you could simply do ; rm $i; aswell, however I tend to be careful about automated removals, unless I know for sure that everything has been accomplished flawlessly I wouldn't remove anything
now if you wanted to remove it, after the mogrify one you could simply do ; rm $i; aswell, however I tend to be careful about automated removals, unless I know for sure that everything has been accomplished flawlessly I wouldn't remove anything
Eagles may soar, but weasels don't get sucked into jet engines...
Thanks Grifter!
One can really learn from you
I actually have a question for you: Is it possible to emulate Windows XP as a Guest OS, but make it possible for Windows XP to see my REAL hardware (Graphic Card, Sound Card and such)? Because I just finished installing Windows XP in QEMU and when I wanted to install the drivers for my Graphic Card, it complained about not finding any cards on my system and I was really pissed-off... I need something like QEMU but which doesn't emulate the whole PC, just the Guest OS.
Thanks in advance!
One can really learn from you
I actually have a question for you: Is it possible to emulate Windows XP as a Guest OS, but make it possible for Windows XP to see my REAL hardware (Graphic Card, Sound Card and such)? Because I just finished installing Windows XP in QEMU and when I wanted to install the drivers for my Graphic Card, it complained about not finding any cards on my system and I was really pissed-off... I need something like QEMU but which doesn't emulate the whole PC, just the Guest OS.
Thanks in advance!
Ok, btw, I ran your script and it worked fine, for the most part. It doesn't want to mogrify files inside directories which have a space in their names.. I tried to fix it but with no success.. Thanks in advance!Grifter wrote:I don't know, xp is the reason I switched to linux, I have never run it and don't intend to