Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • xargs command work only on file lines. So mv is only called on those values. Do you put in your question an example of file names and directories/sub-directories structure and of course an example of what do you expect. Thanks Commented Sep 12, 2021 at 13:13
  • Use the perl rename utility. There are many questions with detailed answers on how to use it here on this site. It can handle any kind of renaming task, from simple sed-like filename transformations (s/old/new/) to a a complex script using any valid perl code. Commented Sep 12, 2021 at 13:30
  • I have used rename utility. But I am unable to use it via text file. I have used multiple options to rename the file using the extensions, specific pattern in the file name, replacing specific characters, finding the names in subdirectories and moving them but none of these condition apply to my query. (using a text file with an old name and new name in the file) Commented Sep 12, 2021 at 13:43
  • You can do this with rename, using perl's open() function to open the files.txt file for read, then iterate over lines in the file and split each line on white-space....but for a job like this, it's probably easier to just write a perl script without using the perl rename tool. or a bash script as in my answer below. Commented Sep 12, 2021 at 17:08