The parameter atime
defines the last access time. Seems you want that? But that is apparently not the same as the date you use in Finder.
See ls -lu
for the date atime
uses.
Mac OS X also uses the "HFS meta data" (or: "Finder info") to store dates. For example: Unix does not store file creation dates. The cdate
in Unix is really the change date (including, for example, changes in access permissions, so cdate
gets a new value in slightly different occasions than the modification date for mdate
). Using this metadata, Mac OS X can still keep the details.
There are several options to show (some of) those dates, like:
stat file.txt
GetFileInfo file.txt
mdls file.txt
Using mdfind
one can search for specific meta data. But it uses the Spotlight index, so I guess it might not find everything.
Like to find files that are excluded from Time Machine backups:
sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"
To search based on the creation date, use kMDItemFSCreationDate
. For the last opened date: kMDItemLastUsedDate
. But note that files which have been created through certain Terminal commands, may not have that meta data set:
echo "Hello world" > ~/Desktop/hello-world.txt
touch ~/Desktop/will-not-be-found.txt
mdfind -onlyin ~/Desktop 'kMDItemFSCreationDate >= $time.this_week'
After opening "will-not-be-found.txt" in Text Edit, you'll see the file after all.
See also the Spotlight Query Syntax.
7z a -r "%DATE:~7,2%.%DATE:~4,2%.%DATE:~-4% Backup".7z
Will create the archive with DD.MM.YYYY Backup.7z
Format.
Explanation: Echoing %DATE%
prints the date in your regional date format setting.
D:\>echo %DATE%
Thu 11/04/2010
By using ~x,y
specifier your are doing an in string/substring extraction of the string - where x
is the starting character and y
number of characters you wish to extract.
On your second point:
I only want to add last modified folder to archive(no matter how many folders exist in directory I just need the latest).
7z u -r "%DATE:~2,2%.%DATE:~5,2%.%DATE:~-4% Backup".7z
should do it.
Best Answer
The most common command for this is
stat(1)
. Some variants, notably GNU stat, allow specification of the output format, which simplifies parsing.