-1

I have many files for that i want to rename them.

Current Name: 5b011351286e8a042b23ffff\5b011351286e8a042b23ffff_130225_145634.xml

Required Name: 5b011351286e8a042b23ffff_130225_145634.xml

I just want to delete the part before the backslash and the forward slash as well.

I have 500 files for which i want to do same.

Yameen
  • 17

3 Answers3

3

Try:

rename -n 's;.*\\;;s' *.xml

If the results are what you want, run it again without -n. To open a terminal press Ctrl Alt T. Navigate to your Desktop folder:

cd ~/Desktop

Then run the first command. You'll get a response like this:

5b011351286e8a042b23ffff\5b011351286e8a042b23ffff_130225_145634.xml renamed as 5b011351286e8a042b23ffff_130225_145634.xml

And a lot of other lines for all the files matching the conditions. If you're satisfied with the output, then run:

rename 's;.*\\;;s' *.xml

Explanation:

  1. rename is a Perl program (and hence which accepts Perl expressions) for renaming files. The -n option will tell rename to show what it will do, without actually doing anything.
  2. The Perl expression s;.*\\;;s means subsitute for all characters (.*) followed by one backslash (\\ - it needs to escaped, since \ has a special meaning) with nothing (the ; divides each section of the expression) while treating the entire input as a single string.
muru
  • 197,895
  • 55
  • 485
  • 740
1

You can use the rename command:

rename 's/^.*[\\\/]//s' *.xml
  • thanks @muru. I put ^ to match filenames beginning like this. Other than that, 100% agree with your proposal :). You have my vote as well for the -n option – Sylvain Pineau Sep 11 '14 at 09:53
  • Does the ^ matter? With a .* and greedy matching, it shouldn't be needed, right? Is there some corner case I'm missing? – muru Sep 11 '14 at 09:56
  • @muru Actually it will allow rename to work with files containing a newline character. I know it's a bit crazy but otherwise you'll get Unsuccessful stat on filename containing newline at /usr/bin/rename line 59. – Sylvain Pineau Sep 11 '14 at 10:07
  • Ah. I modified my answer to handle that using the s modifier. – muru Sep 11 '14 at 10:20
  • 1
    I was about to do the same :) ... and I cannot vote twice! – Sylvain Pineau Sep 11 '14 at 10:22
1

If the length of you file name is same(till the part you want to change) for all the file in this case you can do it easily with the help of Thunar Bulk Rename which comes with Thunar file manager.

Install it using sudo apt-get install thunar

Now open Bullk Rename from Dash. It has various option for how you want to rename your file. In you case I have create a file with the name you have give, adjusted few parameter and renamed it. enter image description here

g_p
  • 18,504
  • HI g_p Thanks for the wonderful reply. May i have the linux coding for only this logic..which is mentioned like remove from the position 24 and to position 49. I want to make a separate GUI application. – Yameen Sep 30 '14 at 16:08
  • see cut command. the logic for above may be echo $filename | cut -c24-49 – g_p Sep 30 '14 at 16:17
  • How to make a GUI application for this type of output dear g_P.. – Yameen Sep 30 '14 at 16:26
  • It is broad topic. If you want to make gui application in c++ , you can use QtCreator. – g_p Sep 30 '14 at 16:36
  • can you pls create a application for me and i want just this output. I want to run this application in ubuntu 12.04 . Kindly i have request. – Yameen Sep 30 '14 at 17:46
  • Sorry buddy. Here we provide support for Ubuntu. But writing a simple application would be really easy. First try yourself. – g_p Sep 30 '14 at 18:12