* rename multiple files at once
@ 2002-08-02 12:49 urgrue
2002-08-02 12:51 ` solved: " urgrue
2002-08-03 7:31 ` Camelia NASTASE
0 siblings, 2 replies; 4+ messages in thread
From: urgrue @ 2002-08-02 12:49 UTC (permalink / raw)
To: admin
simple question...
i have a dir with files like:
001.asd
002.asd
003.asd
how would i do something like:
rename all files matching ^0* to a*
the desired result being:
a01.asd
a02.asd
a03.asd
anyone know?
^ permalink raw reply [flat|nested] 4+ messages in thread
* solved: rename multiple files at once
2002-08-02 12:49 rename multiple files at once urgrue
@ 2002-08-02 12:51 ` urgrue
2002-08-03 7:31 ` Camelia NASTASE
1 sibling, 0 replies; 4+ messages in thread
From: urgrue @ 2002-08-02 12:51 UTC (permalink / raw)
To: admin
sorry, nevermind, i got it:
mmv -r "0*" "a#1"
On 2002.08.02 15:49 urgrue wrote:
> simple question...
> i have a dir with files like:
> 001.asd
> 002.asd
> 003.asd
>
> how would i do something like:
> rename all files matching ^0* to a*
> the desired result being:
> a01.asd
> a02.asd
> a03.asd
>
> anyone know?
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: rename multiple files at once
2002-08-02 12:49 rename multiple files at once urgrue
2002-08-02 12:51 ` solved: " urgrue
@ 2002-08-03 7:31 ` Camelia NASTASE
2002-08-03 10:37 ` Glynn Clements
1 sibling, 1 reply; 4+ messages in thread
From: Camelia NASTASE @ 2002-08-03 7:31 UTC (permalink / raw)
To: urgrue; +Cc: admin
#!/bin/sh
for i in 0*.asd
do
a=`/bin/ls $i| sed s/0/a/`
/bin/mv $i $a
done
test it first please.
hope it helps,
camelia
--
Camelia Nastase
Administrator Retea
Departamentul Internet
ASTRAL TELECOM SA, Sucursala Bucuresti
Tel: 021-3209204 Fax: 021-3209203
>
> simple question...
> i have a dir with files like:
> 001.asd
> 002.asd
> 003.asd
>
> how would i do something like:
> rename all files matching ^0* to a*
> the desired result being:
> a01.asd
> a02.asd
> a03.asd
>
> anyone know?
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: rename multiple files at once
2002-08-03 7:31 ` Camelia NASTASE
@ 2002-08-03 10:37 ` Glynn Clements
0 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2002-08-03 10:37 UTC (permalink / raw)
To: Camelia NASTASE; +Cc: urgrue, admin
Camelia NASTASE wrote:
> #!/bin/sh
>
> for i in 0*.asd
> do
> a=`/bin/ls $i| sed s/0/a/`
> /bin/mv $i $a
> done
1. Using "ls" is unnecessary; "echo" would suffice.
2. If you have bash, you can also eliminate the use of "sed", e.g.
for i in 0*.asd ; do
/bin/mv -- "$i" "a${i#0}"
done
Also, a couple of general scripting tips:
1. Shell variables should usually be enclosed in double quotes,
otherwise you will get undesired behaviour if the value contains
whitespace.
2. If the first argument to a command is a variable, you should allow
for the case where it begins with a dash, e.g. by using "--" (this
isn't any issue in this specific case, as the filename is guaranteed
to begin with a "0").
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-03 10:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-02 12:49 rename multiple files at once urgrue
2002-08-02 12:51 ` solved: " urgrue
2002-08-03 7:31 ` Camelia NASTASE
2002-08-03 10:37 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).