LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-14-2011, 04:14 PM   #1
hashbang#!
Member
 
Registered: Aug 2009
Location: soon to be independent Scotland
Distribution: Debian
Posts: 120

Rep: Reputation: 17
[bash] find printf seconds


Code:
find -type f -printf '%TY-%Tm-%Td %TH:%TM:%TS\t%f\n'
I am trying to produce a file listing with file name and time (HH:MM:SS).

%TS gives me seconds followed by decimal digits:
2010-12-29 20:50:57.0000000000 <name>

Is there any way to just get 2 digits other than piping the find output through sed?
 
Old 01-14-2011, 05:31 PM   #2
cin_
Member
 
Registered: Dec 2010
Posts: 266

Rep: Reputation: 23
find -exec ls -l --time-style

Code:
# find -exec ls -l --time-style='+%H:%M:%S' {} +
More customisation can be found within...
Code:
# man ls
---
EXAMPLE
Code:
# find -exec ls -l --time-style='+%H:%M:%S' {} +
-rw-r--r-- 1 root root  604 16:05:20 ./2011.01.04.infSys
-rw-r--r-- 1 root root  141 17:49:29 ./2011.01.08.infSys
-rw-r--r-- 1 root root  135 11:32:04 ./2011.01.09.infSys
-rw-r--r-- 1 root root  141 18:22:07 ./2011.01.13.infSys
-rw-r--r-- 1 root root  350 04:28:56 ./2011.01.14.infSys
-rw-r--r-- 1 root root   30 03:18:39 ./userlist

.:
total 24
-rw-r--r-- 1 root root 604 16:05:20 2011.01.04.infSys
-rw-r--r-- 1 root root 141 17:49:29 2011.01.08.infSys
-rw-r--r-- 1 root root 135 11:32:04 2011.01.09.infSys
-rw-r--r-- 1 root root 141 18:22:07 2011.01.13.infSys
-rw-r--r-- 1 root root 350 04:28:56 2011.01.14.infSys
-rw-r--r-- 1 root root  30 03:18:39 userlist
#

Last edited by cin_; 01-14-2011 at 05:33 PM.
 
Old 01-14-2011, 06:22 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,456

Rep: Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844
Or
Code:
find -type f -printf '%TY-%Tm-%Td %TH:%TM:%.2TS\t%f\n'
Or (if you don't mind loss of control over format)
Code:
find -type f -printf '%Tc\t%f\n'
Strangely, %Tc is the only directive without fractional seconds, how are fractional seconds ever useful to anyone?

Last edited by ntubski; 01-14-2011 at 08:18 PM. Reason: typo
 
1 members found this post helpful.
Old 01-14-2011, 06:44 PM   #4
hashbang#!
Member
 
Registered: Aug 2009
Location: soon to be independent Scotland
Distribution: Debian
Posts: 120

Original Poster
Rep: Reputation: 17
ntubski - brilliant!

Where are those formatting options documented?

Last edited by hashbang#!; 01-14-2011 at 06:46 PM.
 
Old 01-14-2011, 08:17 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,456

Rep: Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844Reputation: 844
Findutils manual: Print File Information, specifically Time Directives and Time Formats.
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash rounding up numbers with printf gary_in_springhill Programming 5 02-03-2010 01:34 AM
BASH printf and ftp remirez83 Programming 5 01-13-2010 12:56 PM
BASH - printf printing escape codes even though I have %0b defined DevonB Linux - Newbie 5 12-23-2009 01:42 PM
Changes in Latest Core Utils find/printf Command? Woodsman Slackware 4 08-28-2009 04:52 PM
bash printf anyone? gumby Programming 4 05-13-2003 11:51 AM


All times are GMT -5. The time now is 02:08 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration