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.
2 Answers 2
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" {} +
You can do this using the du command in the terminal. See the following discussion for a more detailed explanation:
-
I tried this command but I could not find a way to get time stamp of the files.Juza– Juza2014年03月26日 15:36:19 +00:00Commented Mar 26, 2014 at 15:36
rsync. That will keep date and time. You can make a copy, then check if it's OK, then remove the original files.