display filename with date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display filename with date
# 1  
Old 03-28-2008
display filename with date

Hi buddies,
I have a doubt. I want to display filename with date in the following format.Is there any way to do this. Kindly give me the solution.

I want to display the result in the following manner.
test1.txt 03/28/2008
testlog.log 02/20/2008

Please let me know one solution how to do this.

Thanks in advance
pstanand
# 2  
Old 03-28-2008
Your ls may have localization support which would basically mean if you can find a locale for which this (I would say zany but I'm suppressing it ... oops) date format is standard, that should do it.

Or, you could do something like this:

Code:
perl -e 'for $file (@ARGV) {
    @s = stat $file;
    @d = localtime($s[9]);  # or gmtime; stat[9] is mtime
    printf "$file %02i/%02i/%04i\n", $d[4]+1, $d[3], $d[5]+1900 }' list of files here

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change existing date to current date in a filename?

Suppose i have a list of files in a directory as mentioned below 1. Shankar_04152019_ny.txt 2. Gopi_shan_03122019_mi.txt 3. Siva_mourya_02242019_nd.txt .. . . . . 1000 . Jiva_surya_02282019_nd.txt query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Discussion started by: Shankar455
4 Replies

2. Shell Programming and Scripting

UNIX script to display the filename

Hi All How to answer the below interview question.. With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename (2 Replies)
Discussion started by: shumail
2 Replies

3. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

4. Shell Programming and Scripting

Display the Filename and Size of a File

Hello, all! Working in a Bourne shell. What command would list the filename and size of a file if the size of the file had to be bigger than $a and smaller than $b? Output (if $a is 10 bytes and $b is 50 bytes):test1.txt 15 test2.txt 30 test3.txt 50 Thanks, Ann :p (3 Replies)
Discussion started by: LowlyIntern
3 Replies

5. Shell Programming and Scripting

How to display a date, 30 days from the current date?

Well guys, I know the right syntax for displaying the current date is $(date). However, I am planning to send emails to some customers which displays their subscription date, and then the expiry. The expiry being 30 days from the current date. What would the right syntax be? (6 Replies)
Discussion started by: xxxx
6 Replies

6. Shell Programming and Scripting

Get the oldest date based on date in the filename

I am using ksh93 on Solaris. Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this: 20110501_1.dat 20110501_2.dat 20110501_3.dat... (2 Replies)
Discussion started by: gary_w
2 Replies

7. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

8. UNIX for Dummies Questions & Answers

how to display date with filename??

Hi i am currently using below command in shell script and calling it from cron job. This is to take daily backup with the date as suffix to the file.When i try i unable to get the date suffixed to the backup file. Please help me as to wt's wrong in this or how to get the date added to the... (5 Replies)
Discussion started by: abhi_n123
5 Replies

9. UNIX for Dummies Questions & Answers

Display last 8 character of filename

I would like to display the last 8 characters of the filenames for filenames of different lengths. I can delete the last 8 characters with sed but dont know how to only show the last 8 characters. The filenames are something like; afxH340800340000 afxH30800340021 afxR3080034002122 I... (3 Replies)
Discussion started by: Beanz
3 Replies

10. UNIX for Dummies Questions & Answers

Display filename and wc stats

I'm just learning UNIX and I'm trying to do the following: Write a script called details.bash that, for each file in the working directory, prints the filename, the # of lines, and the # of words to to some output file, like this: filename1 73 431 filename2 5 21 It's probably a stupid... (1 Reply)
Discussion started by: asianmike
1 Replies
Login or Register to Ask a Question