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?
How to change all file extensions in a folder to others
12:56 PM | How to, Linux, Linux commands | 6 comments »
Subscribe to:
Post Comments (Atom)
Hi,
Thanks for the very useful information on file extensions in Linux, it has been very helpful tip for me
Hi
Yes - thx for persons which share their knowledge!
Fritz
Thankyou so much... very useful. Community spirit in action.
Matt
Nice tip, thanks!
Thanks for your tip and your knowledge.It helps me resolve my problem :D
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