Rename children directory and directories

Asked

Viewed 82 times

1

I would like to know how a bash code is made to rename all files of a certain extension and folders that start with a special name. The repository I want to make the changes to:

https://github.com/gnramos/CIC-APC

for example:

1.in -> 01.in 1.out -> 01.out

3_Fluxe -> 03_Fluxe 4_Subalgoritmos -> 04_Subalgoritmos

It’s just these 3 cases, files with extension . in, . out, and folders and start with a number less than 10, if not less than 10, 0 does not need to be added.

  • In your case, the 1.in file would have the new name of 01.in ?

1 answer

0

By accessing each directory, you can rename all the files within it using:

rename 's/^/0/' *, for a specific extension just change the * as rename 's/^/0/' *.in

or also:

for file in $(ls); do mv $file 0${file}; done

Browser other questions tagged

You are not signed in. Login or sign up in order to post.