Skip to content
Advertisement

Linux – add creation Date or DateTime in the name of the file

I have a file on a Linux server which is created automatically. I would like to create a script which will automatically rename the file after it is created on the server, so it will add date or datetime information

For example:

JavaScript

Thank you!

Advertisement

Answer

Try this:

JavaScript

Here is the manpage of date where you can find the different output formats: http://linuxcommand.org/man_pages/date1.html

If you like to rename all the files with a pattern using a script, you could do something like this:

JavaScript

This will find all the files with a name like filename???.pdf (??? is a wildcard for 3 characters) and add the timestamp in front of their names.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement