2

I have 195 files in one other folder. Every single one has a combination of numbers and letters in [] brackets in front of its description. Example: [12hjk534m45] description.

Is it possible to delete the brackets and its contents with a command?

I hoped to do it with rename command and the syntax [abc]?
How would that command look like?

αғsнιη
  • 36,350
flap
  • 73

2 Answers2

1
rename -n 's:^\[.*\](.*):$1:' *

[02Rarev]QgysLJF renamed as QgysLJF
[0rwCtGh]cGdxnWH renamed as cGdxnWH
[1B2CMhq]M91oPHh renamed as M91oPHh
[1BMD7N3]0nYVP0b renamed as 0nYVP0b
[1MjkCZu]WBPYXKG renamed as WBPYXKG
[2HoSmD7]aLWLmpf renamed as aLWLmpf

^\[.*\] matches from beginning^ of files for brackets and everything inside pair of it which is followed by anything(.*). So with (.*) we just captured a group of anything after brackets that contains only files description then in replacement section s/.../REPLACEMENT/ of rename command I replaced all files names with description part by using back-reference of captured group($1 refer to index of first captured group(.*)).

You can also use rename with class of characters matching:

rename -n 's:^\[([0-9A-Za-z]*)\](.*):$1:' *

How to create multiple files with different names and different extensions?

αғsнιη
  • 36,350
0

There's a really brilliant program for doing things like this called GPRename, it's in the software centre.

(Here's info on the commands:

http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal

Looks to like what you want is there but you'll have to figure it out.. or just use GPRename!

great explanation of it here too: How to easily rename files using command line?)

Rabbit
  • 792