Just how do I transform folder timestamps recursively to the latest documents?

I was asking yourself if any person recognizes just how to transform the timestamps of folders recursively based upon the most up to date timestamp located of the documents because folder.

So as an example:

[email protected]:/media/media/MP3s/Foo Fighters/(1997-05-20) The Colour and The Shape$ ls -alF
total 55220
drwxr-xr-x  2 jon jon    4096 2010-08-30 12:34 ./
drwxr-xr-x 11 jon jon    4096 2010-08-30 12:34 ../
-rw-r--r--  1 jon jon 1694044 2010-04-18 00:51 Foo Fighters - Doll.mp3
-rw-r--r--  1 jon jon 3151170 2010-04-18 00:51 Foo Fighters - Enough Space.mp3
-rw-r--r--  1 jon jon 5004289 2010-04-18 00:52 Foo Fighters - Everlong.mp3
-rw-r--r--  1 jon jon 5803125 2010-04-18 00:51 Foo Fighters - February Stars.mp3
-rw-r--r--  1 jon jon 4994903 2010-04-18 00:51 Foo Fighters - Hey, Johnny Park!.mp3
-rw-r--r--  1 jon jon 4649556 2010-04-18 00:52 Foo Fighters - Monkey Wrench.mp3
-rw-r--r--  1 jon jon 5216923 2010-04-18 00:51 Foo Fighters - My Hero.mp3
-rw-r--r--  1 jon jon 4294291 2010-04-18 00:52 Foo Fighters - My Poor Brain.mp3
-rw-r--r--  1 jon jon 6778011 2010-04-18 00:52 Foo Fighters - New Way Home.mp3
-rw-r--r--  1 jon jon 2956287 2010-04-18 00:51 Foo Fighters - See You.mp3
-rw-r--r--  1 jon jon 2730072 2010-04-18 00:51 Foo Fighters - Up in Arms.mp3
-rw-r--r--  1 jon jon 6086821 2010-04-18 00:51 Foo Fighters - Walking After You.mp3
-rw-r--r--  1 jon jon 3033660 2010-04-18 00:52 Foo Fighters - Wind Up.mp3

The folder" (1997-05-20) The Colour and also The Shape" would certainly have its timestamp set to 2010-04-18 00:52.

0
2019-05-04 03:02:29
Source Share
Answers: 2

That's not "recursively", it's simply transforming all the timestamps in a folder. If that's what you suggest, there's 2 actions.

stat -c '%Y' filename will certainly result the timestamp of filename, and also stat -c '%Y %n' * will certainly result the timestamp and also filename of every documents in the folder, so this will certainly locate the filename of one of the most lately changed documents in the existing folder :

mostrecent="`stat -c '%Y %n' * | sort -n | tail -n1 | cut -d ' ' -f '2-'`"
.

On 2nd idea, there's a means less complicated means to get the highest possible timestamp in the folder :

mostrecent="`ls -t | head -n1`"
.

After that you intend to transform all the documents in the folder to have the very same timestamp as that documents. touch -r foo bar will certainly transform bar to have actually the very same changed timestamp as foo, so this will certainly transform all the documents in the folder to have actually the very same changed timestamp as your most lately changed documents :

touch -r "$mostrecent" *
.

So, the one-liner is :

touch -r "`ls -t | head -n1`" *
.
0
2019-05-08 01:11:56
Source

You can make use of touch -r to make use of an additional documents's timestamp as opposed to the existing time (or touch --reference=FILE )

Here are 2 remedies. In each remedy, the first command transforms the alteration time of the directory to that of the latest documents quickly under it, and also the 2nd command considers the entire directory tree recursively. Adjustment to the directory (cd '.../(1997-05-20) The Colour and The Shape' ) prior to running any one of the commands.

In zsh (remove the D to overlook dot files ) :

touch -r *(Dom[1]) .
touch -r **/*(Dom[1]) .

On Linux (or even more usually with GNU locate ) :

touch -r "$(find -mindepth 1 -maxdepth 1 -printf '%T+=%p\n' |
            sort |tail -n 1 | cut -d= -f2-)" .
touch -r "$(find -mindepth 1 -printf '%T+=%p\n' |
            sort |tail -n 1 | cut -d= -f2-)" .

Nonetheless note that those ones think no newline personalities in documents names.

0
2019-05-07 20:30:25
Source