0

Ive been looking for how I can output a list of files of specific folder and the all nested items which is like below. I have no enough disk already so I can not install macports to have tree command. Please advice me.

I would like to have the output like below.

For Example when to make a list of Documents folder:

  • /useraccount/documents/test1/test1.odt 20140326 19:00:00
  • /useraccount/documents/test1/test2.odt 20140326 19:01:00
  • /useraccount/documents/test1/test11/test.odt 20140326 19:05:00
  • /useraccount/documents/test2/test1.odt 20140326 19:02:00
  • /useraccount/documents/test2/test2.odt 20140326 19:01:30
  • /useraccount/documents/test1.odt 20140325 19:01:30

Background:

Why I don't move the files to external drive is that the date has changed by someone at home. A weeks ago, I believe I could see proper date and time and also, I have been used this But I can not find any files has proper date and time. All files has changed. This is not my mistake. I need to keep the date and time before moving.

Juza
  • 1,057
  • 14
  • 27
  • What I don't understand is what you really need. You want the files back with their original date/time? Or you want to know which files have changed? If you want to move files over to another disk and keep the current timestamp, use `rsync`. That will keep date and time. You can make a copy, then check if it's OK, then remove the original files. – SPRBRN Mar 26 '14 at 16:18
  • I just want to have the list of file name, folder name and time stamp under specific folder with sub folders. Anyway, The time stamp has back now without changing anything. – Juza Mar 27 '14 at 04:27

2 Answers2

3

You can use the find command scan the directory, and have it execute stat to print information about each item it finds:

find /useraccount/documents -exec stat -f "%N %Sm" {} +

but the date is in a different format than you want (e.g. "Mar 26 19:00:00 2014" instead of "20140326 19:00:00"). You could also use %m instead of %Sm to get a raw timestamp (seconds since 1970). See man stat for more output options and format choices.

BTW, that command will list directories as well as files; for just files, add -type f at the right place:

find /useraccount/documents -type f -exec stat -f "%N %Sm" {} +
Gordon Davisson
  • 34,084
  • 5
  • 66
  • 70
0

You can do this using the du command in the terminal. See the following discussion for a more detailed explanation:

List directories and their sizes in Mac OS X command line

SPRBRN
  • 7,384
  • 14
  • 61
  • 90