Getting exact time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Getting exact time
# 1  
Old 08-11-2006
Getting exact time

I had a question regarding the creation time stamp (or modified time stamp) of a file. when I use the ls -all command I only get the time in hours:minutes. I'm looking for the time in hours:minutes:seconds . Any ideas??? Thanks in advance!
# 2  
Old 08-11-2006
You have to resort to perl, python or maybe C
Code:
#!/bin/ksh
#tsec.sh
# usage tsec.sh <filename>
perl -e '
  # modify time of the file  mtime = [9] atime =[8] ctime =[10]
	 $mtime = ((stat "$ARGV[0]")[9]);
  # convert mtime to date & time
	 local($sec,$min,$hr,$day,$mon,$yr,$wday,@dntcare) = localtime($mtime);
  # add leading zeroes if needed
	 $yr = ($yr>=70) ? $yr+1900 : $yr+2000;
	 $yr="$yr";	 
     $month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
     $day = ($day < 10) ? "0$day" : "$day";
	 $hr  = ($hr < 10) ? "0$hr" : "$hr";
	 $min = ($min < 10) ? "0$min" : "$min";
	 $sec = ($sec < 10) ? "0$sec" : "$sec";
	 printf "%s %s, %s %s:%s:%s\n", $month,$day,$yr,$hr,$min,$sec;
	 ' "$1"

Fix up the printf statement to format the data the way you want
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Epoch time to produce exact date everytime

so i have to perform a certain task at set times. for instance, i need to run a job at 12:30am every night, and other jobs, i only need to have them run on saturdays. how do i manipulate the date command to give me the epoch equivalence of what 12:30am would be every day? im looking for a... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

3. Shell Programming and Scripting

Exact match and #

Hi friends, i am using the following grep command for exact word match: >echo "sachin#tendulkar" | grep -iw "sachin" output: sachin#tendulkar as we can see in the above example that its throwinng the exact match(which is not the case as the keyword is sachin and string is... (6 Replies)
Discussion started by: neelmani
6 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

How to know the exact running time of script!

Hi All, newbie here, I'm just wondering how can i know the exact running time of my script? Please advise, THanks, (1 Reply)
Discussion started by: nikki1200
1 Replies

6. UNIX for Dummies Questions & Answers

Exact Multiplication

Hi, I am writing a script in Bourne shell #!/bin/sh used=`quota -v | tail -1 | awk '{print $2}'` total=`quota -v | tail -1 | awk '{print $3}'` echo "$used" echo "$total" perc=`expr ${used} / ${total} * 100 | bc` echo "$perc" I want to get a percentage of quota used to total limit I... (5 Replies)
Discussion started by: desai.rishabh
5 Replies

7. UNIX for Dummies Questions & Answers

how can I run something as root (modprobe, to be exact) every time computer starts.

I have the root password for my box, but I'm ignorant. So, every time I start my computer, I have to run this command /sbin/modprobe fuse as su, so that I can do other stuff (like mount remote directories locally using sshfs) I guess there's some file, like .bashrc, only it's applicable... (4 Replies)
Discussion started by: tphyahoo
4 Replies

8. UNIX for Dummies Questions & Answers

How to find out the exact year in "Last modified time" using ls command

Hi, I understand that the ls command with "-l" option generates the "last modified time" of specific directory. However, some generated results displayed the "last modified time" with detail about the last modified year, for example: -rwxrwxrwx+ 1 smith dev 10876 May 16 2005 part2 ... (6 Replies)
Discussion started by: Dophlinne
6 Replies

9. Shell Programming and Scripting

Echo-exact

I'm new to this so please bear with me.. I have a program that generates a string of the binary data of an image. (I mean, if I take the output of the program, paste it into a text editor and save with a PNG extension, it's a valid image.) Now I want to take this string and pipe it into a... (1 Reply)
Discussion started by: matthewwithanm
1 Replies

10. Programming

what is the exact reason ?

please refer the following 2 statements... 1) int i=1,j; j= i++ + i++; 2) int i=1,j; j=++i + ++i; how j becomes 2 and 6 for the above 2 statements respectively ??? ( i guessed j must be 3 and 5) Somebody define the exact reason please.. :( ... (2 Replies)
Discussion started by: shamal
2 Replies
Login or Register to Ask a Question