Linux: how to recursively rename files
One of the most common tasks when it comes to file manipulation is renaming files, to rename one or two files manually is easy, but how we…
One of the most common tasks when it comes to file manipulation is renaming files, to rename one or two files manually is easy, but how we can automate a mass file renaming task?
Scenario: we have a directory with sub-directories that contain files with xlsx extension that we want to change to xls (clarification: we don’t change the format of the file, just the extension for example purposes).
Solution: We can use find, xargs and rename to create an one liner that will do the job$ find . -type f -name "*.xlsx" | xargs -r rename "s/xlsx/xls/"
Explanation:
- find: From current directory searches recursively all files of extension “xlsx”find . -type f -name "*.xlsx"
- xargs: passes output of find to rename as parametersxargs -r
- rename: renames the file using a regular expression as substitution patternrename "s/xlsx/xls/"
Join Medium with my referral link - Konstantinos Patronas
Read every story from Konstantinos Patronas (and thousands of other writers on Medium). Your membership fee directly…