7

I'm looking for a single command to list all files recursively from a given directory along with its modified time. It would also be nice if it can produce output in a tree-like format as produced by tree command.

NOTE: I'm running Red Hat Enterprise Linux Server release 5.

EDIT: The option -D of tree command prints only the date part of the last modification time for past years, though it display date with time for current year. Here, in this case, I'm expecting to print date with time for past years as well.

2
  • You want to show in seconds?
    – quanta
    Oct 10, 2011 at 9:21
  • @quanta: In my case, precision upto minutes is enough.
    – Gnanam
    Oct 10, 2011 at 9:35

4 Answers 4

21

I'm looking for a single command to list all files recursively from a given directory along with its modified time.

$ find /path/to/folder -type f -print0 | xargs -0 ls -l --time-style="+%F %T"

It would also be nice if it can produce output in a tree-like format as produced by tree command. In my case, precision upto minutes is enough.

On my CentOS, Gentoo, ... -D option is already showed in minutes:

$ tree -D
.
├── [Jul 26 14:41]  LICENSE
├── [Jul 26 14:41]  manifests
│   ├── [Oct 10 16:30]  defines
│   │   └── [Jul 26 14:41]  redis source.pp
│   └── [Jul 26 14:41]  init.pp
├── [Jul 26 14:41]  README
└── [Jul 26 14:41]  templates
    ├── [Jul 26 14:41]  redis.conf.erb
    └── [Jul 26 14:41]  redis-server.erb

3 directories, 6 files
4
  • Yes, you're right. Just now I'm also discovering that if the modified date is not a current year, then it is showing only date part without timestamp, as Mon dd yyyy.
    – Gnanam
    Oct 10, 2011 at 9:45
  • Any ideas to make it to display date with time for past years in tree-format style?
    – Gnanam
    Oct 10, 2011 at 10:26
  • AFAIK, there is no way but edit source code and recompile the tree command.
    – quanta
    Oct 10, 2011 at 10:35
  • Though there is no complete answer/solution provided here, atleast the syntax find /path/to/folder ... was helpful. Thus accepting this as answer.
    – Gnanam
    Oct 12, 2011 at 11:55
2

This command lists recursively all files in a given directory with their full modification time:

ls -Rl --time-style=long-iso /path/to/directory

There's no tree-like output in ls but this is pretty close.

1

perhaps this could be a starting point for your solution:

\tree -nf  | awk '{printf $0} {system("stat -c \" [ %y ]\" " $NF )}'| sed -e 's#\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*#\1 ]#g'  2>/dev/null
0

Since Version 1.6.0 (05/24/11), tree supports the --timefmt[=]format option. (-D option outputs strange results, some lines have no hour and minute, and some lines have no year)
For example:

./tree --timefmt='%Y-%m-%d_%H:%M:%S'

[2024-03-19_19:50:43]  .
├── [2024-02-20_16:43:06]  a
├── [2023-12-27_14:20:23]  b
├── [2023-06-06_20:54:17]  c
├── [2023-09-17_19:49:48]  d
├── [2023-12-27_14:21:24]  e
├── [2024-02-12_21:23:56]  f
├── [2024-02-12_23:03:05]  g
├── [2024-02-26_20:50:12]  h
└── [2024-02-25_18:47:28]  i

1 directory, 9 files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .