3

I need to rename my files in Linux from date.time.filename to filename.

Example:

20170310.00.35.06.Samridhi to Samridhi

Zanna
  • 70,465

2 Answers2

2

You could remove the date and time using an exact expression if the format is consistent, then you will be left with the filename part no matter what characters it has.

rename -n 's/^\d{8}\.\d{2}\.\d{2}\.\d{2}\.//' *

remove -n after testing to actually rename the files.

Notes:

  • \d{8} exactly 8 digits
  • \. literal .

Thanks to @terdon for pointing out that in rename we can use \d to represent any digit instead of [0-9]

Zanna
  • 70,465
0

The mv move command is what you need - it'll move a file to another directory and/or rename it (in the same directory).

So in the directory with your file, type:

mv -vi 20170310.00.35.06.Samridhi Samridhi.

The -v option will show you what it's doing, while the -i option will complain if a file with the same name already exist, allowing you to decide if you want to overwrite it or not.

There is also a rename-command, but this is more useful if you have a lot of files that you want to change the name of after som pattern. Eg. files called document.txt.001, document.txt.002, document.txt.003 ... document.txt.050 ; and you'd rather would have files called document-001.txt, document-002.txt and so on.