![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Root Password change | bullz26 | SUN Solaris | 2 | 03-30-2008 11:09 AM |
| How to change ROOT password. | angelofhell | HP-UX | 3 | 02-25-2008 06:44 AM |
| change root password | duke0001 | SUN Solaris | 3 | 02-22-2007 12:10 PM |
| how do i change extension | kswaraj | Shell Programming and Scripting | 2 | 06-28-2004 08:07 PM |
| How to change extension? | prkwan | Shell Programming and Scripting | 4 | 11-16-2002 07:14 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||||
|
Considering the initial requirement (recursively mv .img to .iso),
with zsh: Code:
cd /Users/astrid/NFS/scripts/img2iso/ autoload -U zmv # put it in your .zshrc zmv -n '(**/)(*).img' '$1$2.iso' remove the n flag: Code:
zmv '(**/)(*).img' '$1$2.iso' Code:
find /Users/astrid/NFS/scripts/img2iso -name '*.img' -exec sh -c 'f="${1%.img}.iso"
[ ! -f "$f" ]&&mv "$1" "$f"' - {} \;
Last edited by radoulov; 02-16-2008 at 09:09 AM.. |
|
||||
|
With all this help I know I will get it going!
Thank you so much for your attention, it gives a lot of inspiration. I havn't come around to finish the script yet (it's that other life with kids, laundry, office work etc.) but I'll check back when I'm finished, real soon I hope. By the way, bash seems to be living here: Code:
$ ls -l /bin/bash -rwxr-xr-x 1 root wheel 1068844 Dec 12 2006 /bin/bash (and the same goes for zsh, nice!) |
|
|||||
|
A bit optimized (without the useless sed), parametric and verbose version:
Code:
test ~ $ cat img2iso.sh
#!/bin/bash
#VIDEO_ROOT_DIRECTORY="/Users/astrid/NFS/scripts/img2iso"
VIDEO_ROOT_DIRECTORY="/home/test/video"
IN_EXT=".img"
OUT_EXT=".iso"
for infile in $(find "$VIDEO_ROOT_DIRECTORY" -name "*${IN_EXT}" -type f)
do
echo "----------"
echo "Processing INFILE <$infile>"
n=0
exit=""
suffix=""
while [ ! "$exit" ]
do
newname="${infile%${IN_EXT}}${suffix}${OUT_EXT}"
if [ ! -f "$newname" ]
then
echo "NEW NAME OK! Renaming to <$newname>"
mv "$infile" "$newname"
exit="y"
else
echo "NEW NAME <$newname> already exists! Incrementing suffix"
n=$((n+1))
suffix="-$n"
fi
done
done
And the output before and after execution: Code:
test ~ $ ls -lR /home/test/video /home/test/video: total 16 -rw-r--r-- 1 test test 0 Feb 17 12:00 aaa.img -rw-r--r-- 1 test test 0 Feb 17 12:00 bbb.img -rw-r--r-- 1 test test 0 Feb 17 12:00 bbb.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc.img -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ddd-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ddd.img -rw-r--r-- 1 test test 0 Feb 17 12:00 eee.img drwxr-xr-x 2 test test 4096 Feb 17 12:06 sub1 drwxr-xr-x 2 test test 4096 Feb 17 12:06 sub2 /home/test/video/sub1: total 4 -rw-r--r-- 1 test test 0 Feb 17 12:06 fff.img -rw-r--r-- 1 test test 0 Feb 17 12:06 fff.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg-2.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg.img -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 hhh-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 hhh.img /home/test/video/sub2: total 4 -rw-r--r-- 1 test test 0 Feb 17 12:06 iii.img -rw-r--r-- 1 test test 0 Feb 17 12:06 lll.img -rw-r--r-- 1 test test 0 Feb 17 12:06 mmm.img test ~ $ ./img2iso.sh ---------- Processing INFILE </home/test/video/ccc.img> NEW NAME </home/test/video/ccc.iso> already exists! Incrementing suffix NEW NAME </home/test/video/ccc-1.iso> already exists! Incrementing suffix NEW NAME OK! Renaming to </home/test/video/ccc-2.iso> ---------- Processing INFILE </home/test/video/aaa.img> NEW NAME OK! Renaming to </home/test/video/aaa.iso> ---------- Processing INFILE </home/test/video/sub1/ggg.img> NEW NAME </home/test/video/sub1/ggg.iso> already exists! Incrementing suffix NEW NAME </home/test/video/sub1/ggg-1.iso> already exists! Incrementing suffix NEW NAME </home/test/video/sub1/ggg-2.iso> already exists! Incrementing suffix NEW NAME OK! Renaming to </home/test/video/sub1/ggg-3.iso> ---------- Processing INFILE </home/test/video/sub1/fff.img> NEW NAME </home/test/video/sub1/fff.iso> already exists! Incrementing suffix NEW NAME OK! Renaming to </home/test/video/sub1/fff-1.iso> ---------- Processing INFILE </home/test/video/sub1/hhh.img> NEW NAME OK! Renaming to </home/test/video/sub1/hhh.iso> ---------- Processing INFILE </home/test/video/eee.img> NEW NAME OK! Renaming to </home/test/video/eee.iso> ---------- Processing INFILE </home/test/video/sub2/mmm.img> NEW NAME OK! Renaming to </home/test/video/sub2/mmm.iso> ---------- Processing INFILE </home/test/video/sub2/iii.img> NEW NAME OK! Renaming to </home/test/video/sub2/iii.iso> ---------- Processing INFILE </home/test/video/sub2/lll.img> NEW NAME OK! Renaming to </home/test/video/sub2/lll.iso> ---------- Processing INFILE </home/test/video/bbb.img> NEW NAME </home/test/video/bbb.iso> already exists! Incrementing suffix NEW NAME OK! Renaming to </home/test/video/bbb-1.iso> ---------- Processing INFILE </home/test/video/ddd.img> NEW NAME OK! Renaming to </home/test/video/ddd.iso> test ~ $ ls -lR /home/test/video /home/test/video: total 16 -rw-r--r-- 1 test test 0 Feb 17 12:00 aaa.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 bbb-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 bbb.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc-2.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ccc.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ddd-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 ddd.iso -rw-r--r-- 1 test test 0 Feb 17 12:00 eee.iso drwxr-xr-x 2 test test 4096 Feb 17 12:09 sub1 drwxr-xr-x 2 test test 4096 Feb 17 12:09 sub2 /home/test/video/sub1: total 4 -rw-r--r-- 1 test test 0 Feb 17 12:06 fff-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 fff.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg-2.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg-3.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 ggg.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 hhh-1.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 hhh.iso /home/test/video/sub2: total 4 -rw-r--r-- 1 test test 0 Feb 17 12:06 iii.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 lll.iso -rw-r--r-- 1 test test 0 Feb 17 12:06 mmm.iso |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| linux, linux commands, unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|