How do i collect date and time for list of files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i collect date and time for list of files in a directory
# 1  
Old 06-01-2007
How do i collect date and time for list of files in a directory

How do i collect date and time for list of files in a directory using AWK Command
# 2  
Old 06-01-2007
Code:
$ ls -l
total 304
drwxr-xr-x   2 training staff        512 Jun 01 11:28 SNMP1
drwxr-xr-x   2 training staff        512 Jun 01 11:28 SNMP2
-rw-r--r--   1 training staff         42 May 25 15:33 a
-rw-r--r--   1 training staff          8 May 25 15:33 b
-rw-r--r--   1 training staff         72 Jun 01 11:15 f
-rw-r--r--   1 training staff        930 May 21 11:15 ff
-rw-r--r--   1 training staff      72546 Apr 28 13:05 ff2
-rw-r--r--   1 training staff         34 May 24 14:45 file
-rwxrwxrwx   1 training staff         62 May 24 16:18 s
-rwxr-xr-x   1 training staff         40 May 24 16:17 ss
drwxr-xr-x   2 training staff        512 May 09 17:50 tmp
drwxr-xr-x   2 training staff        512 Jun 01 11:28 tmp1
-rw-r--r--   1 training staff          0 May 22 12:02 x a
$ ls -l | awk ' NF > 2 { print $6,$7,$8 } '
Jun 01 11:28
Jun 01 11:28
May 25 15:33
May 25 15:33
Jun 01 11:15
May 21 11:15
Apr 28 13:05
May 24 14:45
May 24 16:18
May 24 16:17
May 09 17:50
Jun 01 11:28
May 22 12:02

# 3  
Old 06-01-2007
Laknar,
Be advised that if the file is more than six months old,
in place of time it will be the year:
Code:
-r--r--r--   1 mmzes sdev    23093 Feb 20 11:30 abc.sh
-rw-r-----   1 mmzes sdev     1372 Jan 19 13:21 a
-rw-r-----   1 mmzes sdev      683 Jan 19 13:21 b
-r-xr-xr-x   1 mmzes sdev     4341 Jan 17 14:43 file1
-r--r--r--   1 mmzes sdev     3055 Oct 31  2006 file2
-r-xr-xr-x   1 mmzes sdev    11350 Aug 17  2006 ab.sh
-r--r--r--   1 mmzes sdev     7208 Jul 27  2006 st.sh
-r-xr-xr-x   1 mmzes sdev     8492 Jul 18  2006 ad.txt


Last edited by Shell_Life; 06-01-2007 at 03:04 PM..
# 4  
Old 06-01-2007
To get around ls -l date formatting try a perl shell function maybe like this:
Code:
#!/bin/ksh

filedate()
{
	perl -e '
	     @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
	     $mtime = (stat $ARGV[0])[9];
	     ($sec, $min, $hr, $mday, $mon, $yr, $wday, $yday, $dntcare) =
	         localtime($mtime);
	     printf "%s %02d %d %02d:%02d:%02d\n", 
	         $months[$mon], $mday, $yr + 1900, $hr, $min, $sec;
	' "$1"
}


for file in $(ls $@ )
do
    filedate "$file"
done

# 5  
Old 06-01-2007
you can also use the stat command to get file date/time information , only if your system has it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

2. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

3. Shell Programming and Scripting

How to collect the logs with in two time stamp ?

Hi Gurus I need to collect the logs between two time stamp... The log files 12 hours format (ex- Nov 14, 2013 12:10:16 AM UTC) I tried the below commands but no luck. awk '$0 >= "Nov 14, 2013 9:40:01" && $0 <= "Nov 14, 2013 9:55:01"' file sed -n '/Nov 14, 2013 7:58:00 PM UTC/,/Nov 14, 2013... (5 Replies)
Discussion started by: zenkarthi
5 Replies

4. Shell Programming and Scripting

To get the files in a directory for the given date (User entered date)

Need a ksh script to get the files that were created or modified in a directory on a particular date entered by the user. For example if a directory contains files as below : > ll total 41 -rw-rw-r-- 1 psn psn 199 Aug 23 07:06 psn_roll.sh -rw-rw-r-- 1 psn psn ... (10 Replies)
Discussion started by: ramprabhum
10 Replies

5. Shell Programming and Scripting

List Files Based On Time & Date

Hi All, I am using HP Unix. I want to list files which are created 5 minutes before on the same day as well as before today's date. I checked all the forums and the commands provided there does not work on HP Unix. Can you please help me on this? Your help is highly aprreciated. Thanks and... (3 Replies)
Discussion started by: angshuman
3 Replies

6. Shell Programming and Scripting

How to collect all the list of files along with the permissions

Hi guys, I have one problem. I need collect the list files along with the file permissions in all directories in one server. Is their any easy way to collect using any commands or any scripts? Advance Thanks :) (2 Replies)
Discussion started by: kartheek
2 Replies

7. UNIX for Dummies Questions & Answers

How to always display date/time regardless of directory?

I found via Google a way to show the date and time stamp once I log in. However, whenever I cd to another directory it doesn't display the correct path. Here are the relevant parts from my .kshrc : unset _h _m _s eval $(date "+_h=%H ;_m=%M ;_s=%S") ((SECONDS =... (3 Replies)
Discussion started by: Mike F.
3 Replies

8. UNIX for Dummies Questions & Answers

List files with date and time stamps only

Hi there, I'm using terminal on mac and using the ls -l command to list all the files in a directory. However, I only want to display the date and time stamp of each file rather than permissions, owner, group etc... Is this possible? Many thanks in advance Dave (2 Replies)
Discussion started by: davewg
2 Replies

9. Shell Programming and Scripting

How do i collect Date & Time from Different Directories in a script

How do i collect Date & Time from Different Directories in a script The script iam using for a single directory is : ls -l | grep awk '{print $8}' (2 Replies)
Discussion started by: laknar
2 Replies

10. Shell Programming and Scripting

List files created between specific date and time

Hi I need to write a script to list files in a directory created within specific date and time for eg list files created between Apr 25 2007 11:00 to Apr 26 2007 18:00. and then i have to count them Any suggestions pls ? (3 Replies)
Discussion started by: jazjit
3 Replies
Login or Register to Ask a Question