• Home
  • SEM
    • PPC
    • SEO
    • How To
  • Bangladesh
  • School
    • HTTP
    • REP
    • Bots n’ htaccess
    • Source Code
    • Excel 2010
    • HTML XHTML Entities
    • Gmail Operators
    • HTML & ASCII
  • About
    • Privy
    • About This Blog
  • Contact
  • বাংলা

Saidul Hassan

Digital Marketing Evangelist

Home / Bangladesh / How to add an extension to all files via terminal

How to add an extension to all files via terminal

25 Jun, 2021 By Saidul Hassan · Filed Under: Bangladesh

Say you would like to add the .png extension to all files.
rename 's/$/.png/' *

Source: http://askubuntu.com/questions/74011/how-to-add-an-extension-to-all-files-via-terminal

Now recursively add file extension to all files!

For example, you have a few directories and sub-directories containing files with no file extension. And you want to add .jpg to all the files contained within these directories.
This one will add extension to all files, with or without extension:
find . -type f -exec mv '{}' '{}'.jpg \;
Explanation: this recursively finds all files (-type f) starting from the current directory (.) and applies the move command (mv) to each of them. Note also the quotes around {}, so that filenames with spaces (and even newlines…) are properly handled.
And this will find files without extension and add .jpg
find /path -type f -not -name "*.*" -exec mv "{}" "{}".jpg \; -this skips files which already have an extension.

An alternative that’s believed to be more efficient in execution using the find | xargs :
find /path -type f -not -name "." -print0 | xargs -0 rename 's/(.)$/$1.jpg/'
Note that this requires the version of rename found in Debian-flavored distros (aka prename), rather than the traditional rename. It’s just a tiny perl script, though, so it would be easy enough to use the command above on any system.

Source: http://stackoverflow.com/questions/1108527/recursively-add-file-extension-to-all-files

The following two tabs change content below.
  • Bio
  • Latest Posts
My Twitter profileMy Facebook profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Saidul Hassan

Managing Partner at Up Arrow Consulting
COO at Up Arrow Consulting, MCC manager, & Technical SEO consultant. Certified Google Partners and Microsoft Bing Ads Accredited Professional, Python enthusiast, wannabe SysAdmin. Graduated from School of Management & Business Administration (SOMBA), Khulna University.
My Twitter profileMy Facebook profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Latest posts by Saidul Hassan (see all)

  • Batch script to create directories & moving fixed number of files to those directories - 30 Apr, 2021
  • How to use PrismJS syntax highlighter on WordPress without plugin - 30 Mar, 2020
  • Download an Entire Website for Offline Viewing - 26 Nov, 2019

Share:

  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Pocket
  • Email
  • Print

First published on 24 Jun, 2015 · Last updated 25 Jun, 2021 ·

Batch script to create directories & moving fixed number of files to those directories

30 Apr, 2021 By Saidul Hassan

How to use PrismJS syntax highlighter on WordPress without plugin

30 Mar, 2020 By Saidul Hassan

Download an Entire Website for Offline Viewing

26 Nov, 2019 By Saidul Hassan

How to color highlight .htaccess files in Xed/Gedit

20 Aug, 2018 By Saidul Hassan

HMA Pro VPN Setup for Multiple Locations without User/Password Every time in Linux CLI

14 May, 2018 By Saidul Hassan

  • ♥ Bangladesh ♥
    Log in · Privacy Policy · Contact
    Copyright © 2011 Saidul Hassan

  • DMCA