LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [bash] find printf seconds (https://www.linuxquestions.org/questions/programming-9/%5Bbash%5D-find-printf-seconds-856387/)

hashbang#! 01-14-2011 04:14 PM

[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?

cin_ 01-14-2011 05:31 PM

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
#


ntubski 01-14-2011 06:22 PM

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? :scratch:

hashbang#! 01-14-2011 06:44 PM

ntubski - brilliant!

Where are those formatting options documented?

ntubski 01-14-2011 08:17 PM

Findutils manual: Print File Information, specifically Time Directives and Time Formats.


All times are GMT -5. The time now is 03:59 AM.