This can be done with some light scripting and this article will show you how to do exactly that.

Many other semi-automated systems produces similar date and time based filenames.

This also applies to other domains and sets of files.

Terminal window showing the manual page for the Mutt email client on Linux

Many other commands tried all had limitations which I wanted to avoid.

hey do your own research before running it.

I also checked a file named

which contains a newline.

synology nas

Let’s first look at how this works, and then analyze the command.

The command assumes you do not have any1.pdftox.pdfnamed files yet.

Let’s look at the command in detail.

Article image

Shutterstock/estherpoon

At the start of the oneliner it does asafety checkusing anifstatement to ensure that both_eand_cfiles are not present.

If there is a file with that name, the script will not proceed.

Such interference is best avoided when it comes to renaming many files!

Bulk Rename Files to Numeric File Names in Linux

The second one was thatxargsin combination withbash -cseems to have a limitation in variable handling inside thebash -ccommand line.

Even extensive research online did not provide a workable solution for this.

Thus, I ended up using a small file_cwhich keep progress.

xargs with -t option lets us see what is happening during the rename process

This is ensured by the-print0option tofind, and by the-0option to xargs.

The dot is already included in the later*.$(cat _e)-namespecifier tofind.

To obtain the contents of the two files, a simplecatcommand is used, executed from within a subshell.

Themvmove command uses-nto avoid overwriting any file already present.

Finally we cleanup the two temporary files by removing them.

Yet other solutions missed handling files with spaces, newlines and special characters like '' correctly.