Sponsored Content
Top Forums Shell Programming and Scripting Adding date and time to file name Post 302471745 by michaelrozar17 on Monday 15th of November 2010 02:20:04 AM
Old 11-15-2010
Store the file's extension in a variable before mv command and substitute in the variable later while using mv command.

Code:
#!/bin/bash

thetime=`date +%Y-%m-%d--%H:%M:%S` #
for i in *.*
do 
	extn=${i##*.} # save the extension of the file
	mv $i ${i%.*}$(date "+_%Y%m%d.${extn}")
done

This User Gave Thanks to michaelrozar17 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

2. Shell Programming and Scripting

problem with displaying date and adding time

Hi, I have a log file with contents like 81.49.74.131 - - 81.49.74.131 - - 116.112.52.31 - - 116.112.52.31 - - I need an output like this 81.49.74.131 14/Sep/2008 Time duration: 00:06:00 116.112.52.31 15/Sep/2008 Time duration: 00:00:01 Please anyone suggest a script for this.... (1 Reply)
Discussion started by: FuncMx
1 Replies

3. UNIX for Dummies Questions & Answers

Adding date and time to a log file

Morning all Im hoping you can help me. We have a nice new oracle server :( and are needing to move some files around for EDI and BACS. The server runs windows but has an app called MKS toolkit installed which give unix commands. (Needed for the oracle stuff) I have had a go using dos commands... (2 Replies)
Discussion started by: ltodd2
2 Replies

4. UNIX for Dummies Questions & Answers

adding date to a file during FTP

I have a very basic question here. I have to FTP a file from a AIX unix box to a windows server. But during that I have to rename the file. For example: I have to FTP a file called ORDER.TXT from unix and it should go as ORDER_20090101.TXT on to the windows server. It is not possible to... (5 Replies)
Discussion started by: vara32
5 Replies

5. UNIX for Dummies Questions & Answers

Adding Date & time stamps to filename

I need to edit the file name with date and time while writing the script. please help. (1 Reply)
Discussion started by: manish.s
1 Replies

6. Shell Programming and Scripting

adding a date to the last of each file name

i have some files in my directory....wit names say aaa, bbb, ccc,,,,, i want to make loop so that for each file name,,,,,,a sysdate should be appended in the end.........and the files should look like aaa_20100331 i knw date can be appended as `date +"%Y%m%d"` but m nt able to make a loop. ... (2 Replies)
Discussion started by: amitpta
2 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Adding time stamp to file name

I have the awk awk -F\* '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f="sample" ++i} ; $1=$1; print>f}' OFS=\| <filename> How to add the time stamp to the file name mentioned as "sample" Please view this code tag video for how to use code tags when posting code and data. (6 Replies)
Discussion started by: atlantis_yy
6 Replies

8. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

9. Shell Programming and Scripting

Adding date to file

I want this: 0.0230769,0.407692,0.307692,0,0.1,1.4,1,0,ADD DATE HERE, im getting this: 11/02/12 0.00192308,0.0269231,0.0192308,0,0.1,1.4,1,0, my script: #!/bin/ksh DIR=/export/home/yani_m/scripts/scrip_out_put/ DIR2=/export/home/yani_m/scripts/scrip_out_put/calc/ Date=$1... (1 Reply)
Discussion started by: LucyYani
1 Replies

10. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies
Env::PS1(3pm)						User Contributed Perl Documentation					     Env::PS1(3pm)

NAME
Env::PS1 - prompt string formatter SYNOPSIS
# use the import function use Env::PS1 qw/$PS1/; $ENV{PS1} = 'u@h $ '; print $PS1; $readline = <STDIN>; # or tie it yourself tie $prompt, 'Env::PS1', 'PS1'; # you can also tie a scalar ref $format = 'u@h$ '; tie $prompt, 'Env::PS1', $format; DESCRIPTION
This package supplies variables that are "tied" to environment variables like 'PS1' and 'PS2', if read it takes the contents of the variable as a format string like the ones bash(1) uses to format the prompt. It is intended to be used in combination with the various ReadLine packages. EXPORT
You can request for arbitrary variables to be exported, they will be tied to the environment variables of the same name. TIE
When you "tie" a variable you can supply one argument which can either be the name of an environement variable or a SCALAR reference. This argument defaults to 'PS1'. METHODS
"sprintf($format)" Returns the formatted string. Using this method all the time is a lot less efficient then using the tied variable, because the tied variable caches parts of the format that remain the same anyway. FORMAT
The format is copied mostly from bash(1) because that's what it is supposed to be compatible with. We made some private extensions which obviously are not portable. Note that this is not the prompt format as specified by the posix specification, that would only know "!" for the history number and "!!" for a literal "!". Apart from the escape sequences you can also use environment variables in the format string; use $VAR or "${VAR}". The following escape sequences are recognized: a The bell character, identical to "07" d The date in "Weekday Month Date" format D{format} The date in strftime(3) format, uses POSIX e The escape character, identical to "33" Newline Carriage return s The basename of $0 The current time in 24-hour format, identical to "D{%H:%M:%S}" T The current time in 12-hour format, identical to "D{%I:%M:%S}" @ The current time in 12-hour am/pm format, identical to "D{%I:%M %p}" A The current time in short 24-hour format, identical to "D{%H:%M}" u The username of the current user w The current working directory W The basename of the current working directory $ "#" for effective uid is 0 (root), else "$" dd The character corresponding to the octal number 0dd \ Literal backslash H Hostname, uses Sys::Hostname h First part of the hostname l The basename of the (output) terminal device name, uses POSIX, but won't be really portable. [ ] These are used to encapsulate a sequence of non-printing chars. Since we don't need that, they are removed. Extensions The following escapes are extensions not supported by bash, and are not portable: L The (output) terminal device name, uses POSIX, but won't be really portable. C{colour} Insert the ANSI sequence for named colour. Known colours are: black, red, green, yellow, blue, magenta, cyan and white; background colours prefixed with "on_". Also known are reset, bold, dark, underline, blink and reverse, although the effect depends on the terminla you use. Unless you want the whole commandline coloured you should end your prompt with "C{reset}". Of course you can still use the "raw" ansi escape codes for these colours. Note that "bold" is sometimes also known as "bright", so "C{bold,black}" will on some terminals render dark grey. If the environment variable "CLICOLOR" is defined but false colours are switched off automaticly. P{format} Proc information. All of these are unix specific %a Acpi AC status '+' or '-' for connected or not, linux specific %b Acpi battery status in mWh, linux specific %L Load average %l First number of the load average %t Acpi temperature, linux specific %u Uptime %w Number of users logged in Not implemented escapes The following escapes are not implemented, because they are application specific. j The number of jobs currently managed by the application. v The version of the application. V The release number of the application, version + patchelvel ! The history number of the next command. This escape gets replaced by literal '!' while a literal '!' gets replaces by '!!'; this makes the string a posix compatible prompt, thus it will work if your readline module expects a posix prompt. # The command number of the next command (like history number, but minus the lines read from the history file). Customizing If you want to overload escapes or want to supply values for the application specific escapes you can put them in %Env::PS1::map, the key is the escape letter, the value either a string or a CODE ref. If you map a CODE ref it normally is called every time the prompt string is read. When the escape is followed by an argument in the format string (like "D{argument}") the CODE ref is called only once when the string is cached, but in that case it may in turn return a CODE ref. BUGS
Please mail the author if you encounter any bugs. AUTHOR
Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org> This module is currently maintained by Ryan Niebur <rsn@cpan.org> Copyright (c) 2004 Jaap G Karssenberg. All rights reserved. Copyright (c) 2009 Ryan Niebur. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Env, Term::ReadLine::Zoid perl v5.10.0 2009-06-25 Env::PS1(3pm)
All times are GMT -4. The time now is 10:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy