Append date to filename in linux

Asked
Active3 hr before
Viewed126 times

6 Answers

filename
90%

This script copies filename.ext to filename-date.ext, there is another that moves filename.ext to filename-date.ext, you can download them from here. Hope you find them useful!!,oh i almost forgot to add that the script or command should update the filename to a new date everytime you want to save the file into a specific folder but still keeping the previous files. So there would be files like this in the folder eventually: filename_18Oct2009.txt , filename_9Nov2009.txt , filename_23Nov2009.txt, Can you give some more details on precisely what you want to do. So you have a file in a directory which you want to date stamp in this way. Is it just one file with the same name each time or could it be a number of files with a number of different name? – Dave Webb Nov 25 '09 at 10:47 , I'm still not clear on what you want to do. It says the script should update the filename "everytime you want to save the file into a specific folder". What is saving the file into the folder? Where is it coming from? – Dave Webb Nov 25 '09 at 11:00

You can use backticks.

$ echo myfilename - "`date +" % d - % m - % Y "`"

Yields:

myfilename - 25 - 11 - 2009
load more v
88%

Now we can append the current date stored in $now to a filename as follows: echo "Coping data to /tmp/filename-${now} ...",You learned how to add the date to a filename under Linux or Unix-like operating systems. For further information type the following man command: man date,Finally, you can create a filename as follows:,I wrote the following script to save the screenshots with date and time in the filename similar as in Mac OS X:

date + "%FORMAT_STRING"
date + "%m_%d_%Y"
date + "%Y-%m-%d"
load more v
72%

However all I get is the name of the file, and it appends nothing. How do I append a current date to a filename?,Thanks for contributing an answer to Unix & Linux Stack Exchange!,Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.,I'm trying to append the current date to the end of a file name like this:

More than likely it is your use of set. That will assign 'today', '=' and the output of the date program to positional parameters (aka command-line arguments). You want to just use C shell (which you are tagging this as "bash", so likely not), you will want to use:

today = `date +%Y-%m-%d.%H:%M:%S`
# or whatever pattern you desire
load more v
65%

I need to create a shell script that appends a timestamp to existing file. I mainly use Mac OS X for development. Wanted to create the same on Mac Terminal.,Here are some basics on date command.,Some of my Favorite JavaScript Tips and Tricks Tutorials ,Linux and Unix Tutorials shell script

I need to create a shell script that appends a timestamp to existing file. I mainly use Mac OS X for development. Wanted to create the same on Mac Terminal.

Here are some basics on date command.

date
75%

FILE = "backup_$(date +%Y%m%d_%H%M%S)"
40%

Originally published at: https://www.cyberciti.biz/faq/unix-linux-appleosx-bsd-shell-appending-date-to-filename/ How do I append current date (mm_dd_yyyy format) to a filename (e.g., backup_mm_dd_yyyy.sql) under Linux and UNIX like operating systems? How can I append a current date from a variable to a filename under Linux or Unix bash shell? How do I append date to filename?,No reasons. You can use - and any other valid characters. For example, the following in not a valid filename:

No reasons. You can use - and any other valid characters. For example, the following in not a valid filename:

now = $(date + "%m/%d/%Y")
file = "/tmp/backup-${now}"
# # the following is going to fail # #
touch "${file}"
ls - l / tmp / backup *
load more v

Other "filename-undefined" queries related to "Append date to filename in linux"