-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.

marked as duplicate by zwets, Eric Carvalho, Radu Rădeanu, Richard, Eliah Kagan Sep 12 '14 at 7:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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.
  • Pls i want to do it in ubuntu terminal. – Yameen Sep 11 '14 at 10:58
  • @Yameen the command is to be run in a terminal. – muru Sep 11 '14 at 11:03
  • i am a beginner level user of ubuntu i don't understand this command can you pls help in details. I have these files on my desktop in folder. – Yameen Sep 11 '14 at 11:49
  • @Yameen That will take a while, and I'm on a phone now. I think you should comment on Sylvain's answer for a quicker response. – muru Sep 11 '14 at 11:52
  • @Yameen have a look now. – muru Sep 11 '14 at 15:58
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 9: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 9: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

  • 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.