Question on rename command

5 views
Skip to first unread message

Adam Khoob

unread,
Aug 3, 2021, 5:44:00 AM8/3/21
to Umbclug
Good afternoon,

is there any way to rename a file with the current file name but just remove part of it.

for example, I want all files which end with dev to be renamed and remove "dev" substring.

thanks so much for any help.



Rouben Rostamian

unread,
Aug 3, 2021, 9:00:00 AM8/3/21
to Adam Khoob, Umbclug
This one will do until a more clever one comes along:

find . -name '*.dev' -print0 | xargs -0 -I % sh -c 'mv % ` basename % .dev`'

(I know zero about perl but I can bet that there is a shorter solution in perl.)

--
Rouben Rostamian

Mark Perks

unread,
Aug 3, 2021, 12:14:41 PM8/3/21
to Rouben Rostamian, Adam Khoob, Umbclug

Hi Rouben! And you too Morty (and Adam)! Hope all is well,

I know less about Perl, and this is not clever but an alternative not
necessarily better, change to the directory where the files are and use
bin/ls;expr instead of find|xargs.

for i in `/bin/ls -1 *.dev`; do j=`expr $i : '\(.*\)'\.dev`; mv $i $j; done


H. Mark Perks, Ph.D. MEYR 549C
Dept of Chemistry and Biochemistry 410 455-2789
UMBC pe...@umbc.edu
Baltimore, MD 21250
> --
> You received this message because you are subscribed to the Google Groups "UMBC Linux Users' Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to umbclug+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/umbclug/YQk9yyi7b3RP0HE4%40shadow.
>
Reply all
Reply to author
Forward
0 new messages