Today, I will show you a simple way to change all files inside a folder from this extension to another one. This post also applied to other actions such as copying, removing to manage and organize your Linux file system more effectively.

To make sure that you do not destroy your real files, I use the folder /tmp resided the home directory to carried out this tutorial. You can create a new one if you like.

cd
mkdir /tmp
cd tmp

Now, I'm standing in the folder /tmp. Currently, this is a empty working directory. I make 100 new files in the extension .dot as the following:

for x in {1..100}; do touch "file$x.dot"; done

And 200 new files as Gif images

for x in {1..200}; do touch "myimage$x.gif"; done

Now, how can I rename all files .dot to .bak in the folder /tmp? The following command can solve this problem.

for x in *.dot; do mv "$x" "${x%.dot}.bak"; done

Do you love Linux commands?

6 comments

  1. Anonymous // 3/5/08, 8:43 AM  

    Hi,

    Thanks for the very useful information on file extensions in Linux, it has been very helpful tip for me

  2. Anonymous // 8/22/08, 12:49 PM  

    Hi

    Yes - thx for persons which share their knowledge!

    Fritz

  3. Anonymous // 2/17/09, 1:09 AM  

    Thankyou so much... very useful. Community spirit in action.

    Matt

  4. Anonymous // 5/29/09, 5:57 AM  

    Nice tip, thanks!

  5. Anonymous // 4/9/10, 6:47 PM  

    Thanks for your tip and your knowledge.It helps me resolve my problem :D

  6. potato(*_0)... // 4/9/10, 6:58 PM  

    Nice tip!But I have a question : How do you change a folder that contains, for example : YouandI.mp3, Metoyou.mp3 to use only file name : YouandI ?Because I think the command above only apply for filename "$x" where x is a number?Correct me if I'm wrong :D
    Anyway, I'll try your tip for my problem.Thanks