You can use bash
with the globstar
option enabled as in the following script:
#!/bin/bash
shopt -s globstar
for i
do for k in **/"$i"*/
do stat -c "the folder %n was modified on %y" "$k"
done
done
Save it as script
, make it executable with chmod +x script
and call it as you wanted it:
bash /path/to/script testRegex Pub
Note that this will search for e.g. Pub*
, if you actually want to match *Pub*
, change **/"$i"*/
to **/*"$i"*/
. If you want to shorten the timestamp, try adding | sed 's/:[^:]*$//'
to the end of the do stat
line. You should also try %N
instead of %n
, especially when it comes to directory names with spaces this format is preferable.
If you want more fine-grained control over the date format you can use date
, substitute the do stat
line with the following:
do date -d@$(stat -c%Y "$k") +"the folder $k was modified on %b %d %R"
You can then use the usual date
format sequences explained in man date
, this one here prints e.g. May 15 01:19
as you requested.
Last but not least, to pretty-print the output of any of the above you can insert a tab after the directory name and use column
as follows:
#!/bin/bash
shopt -s globstar
for i
do for k in **/"$i"*/
do date -d@$(stat -c%Y "$k") +"the folder $k%twas modified on %b %d %R"
done
done | column -ts$'\t'
Example run
$ tree
.
├── 1
│ └── 1
│ └── 1
├── 1something
└── 2
└── 1
$ bash -O globstar -c 'for i; do for k in **/"$i"*/; do stat -c "the folder %n was modified on %y" "$k"; done; done' _ 1
the folder 1/ was modified on 2018-06-07 09:45:28.098693507 +0200
the folder 1/1/ was modified on 2018-06-07 09:45:28.098693507 +0200
the folder 1/1/1/ was modified on 2018-06-07 09:45:28.098693507 +0200
the folder 1something/ was modified on 2018-06-07 09:55:36.066531665 +0200
the folder 2/1/ was modified on 2018-06-07 09:45:28.098693507 +0200
$ bash -O globstar -c 'for i; do for k in **/"$i"*/; do stat -c "the folder %n was modified on %y" "$k" | sed 's/:[^:]*$//'; done; done' _ 1
the folder 1/ was modified on 2018-06-07 09:45
the folder 1/1/ was modified on 2018-06-07 09:45
the folder 1/1/1/ was modified on 2018-06-07 09:45
the folder 1something/ was modified on 2018-06-07 09:55
the folder 2/1/ was modified on 2018-06-07 09:45
$ bash -O globstar -c 'for i; do for k in **/"$i"*/; do date -d@$(stat -c%Y "$k") +"the folder $k was modified on %b %d %R"; done; done' _ 1
the folder 1/ was modified on Jun 07 09:45
the folder 1/1/ was modified on Jun 07 09:45
the folder 1/1/1/ was modified on Jun 07 09:45
the folder 1something/ was modified on Jun 07 09:55
the folder 2/1/ was modified on Jun 07 09:45
$ bash -O globstar -c 'for i; do for k in **/"$i"*/; do date -d@$(stat -c%Y "$k") +"the folder $k%twas modified on %b %d %R"; done; done | column -ts'"$'\t'" _ 1
the folder 1/ was modified on Jun 07 09:45
the folder 1/1/ was modified on Jun 07 09:45
the folder 1/1/1/ was modified on Jun 07 09:45
the folder 1something/ was modified on Jun 07 09:55
the folder 2/1/ was modified on Jun 07 09:45
%Tb %Td %TH:%TM
(e.g.May 15 01:19
) instead of%t
gives a format like OP requested. – dessert Jun 07 '18 at 08:43