shell to print modification date of all directories name match pattern

Clash Royale CLAN TAG#URR8PPP up vote
4
down vote
favorite
I want to write a shell program which will go through all folders whose names match a pattern like this:
sudo sh shell.sh pub
When run, the script will look for all folders whose name contains pub and print its modification date.
I wish to have code which will print results like in this image:
I have this code but it is not giving me the result I expect.
echo 'the folder '$1' was modified at ';
find -type d -name 'kam*' -exec stat -c '%y %n' '' ;
I must go through every folder and output text echo 'the file '$1' was modified at '; and print the date like in the image.
I would like a result like this:
netcom@hotspot:~$ bash script.sh testRegex Pub
the folder testRegex was modified on may 15 01:19
the folder Public was modified on may 19 01:19
the folder Pubos was modified on may 19 01:19
14.04 command-line bash
add a comment |Â
up vote
4
down vote
favorite
I want to write a shell program which will go through all folders whose names match a pattern like this:
sudo sh shell.sh pub
When run, the script will look for all folders whose name contains pub and print its modification date.
I wish to have code which will print results like in this image:
I have this code but it is not giving me the result I expect.
echo 'the folder '$1' was modified at ';
find -type d -name 'kam*' -exec stat -c '%y %n' '' ;
I must go through every folder and output text echo 'the file '$1' was modified at '; and print the date like in the image.
I would like a result like this:
netcom@hotspot:~$ bash script.sh testRegex Pub
the folder testRegex was modified on may 15 01:19
the folder Public was modified on may 19 01:19
the folder Pubos was modified on may 19 01:19
14.04 command-line bash
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I want to write a shell program which will go through all folders whose names match a pattern like this:
sudo sh shell.sh pub
When run, the script will look for all folders whose name contains pub and print its modification date.
I wish to have code which will print results like in this image:
I have this code but it is not giving me the result I expect.
echo 'the folder '$1' was modified at ';
find -type d -name 'kam*' -exec stat -c '%y %n' '' ;
I must go through every folder and output text echo 'the file '$1' was modified at '; and print the date like in the image.
I would like a result like this:
netcom@hotspot:~$ bash script.sh testRegex Pub
the folder testRegex was modified on may 15 01:19
the folder Public was modified on may 19 01:19
the folder Pubos was modified on may 19 01:19
14.04 command-line bash
I want to write a shell program which will go through all folders whose names match a pattern like this:
sudo sh shell.sh pub
When run, the script will look for all folders whose name contains pub and print its modification date.
I wish to have code which will print results like in this image:
I have this code but it is not giving me the result I expect.
echo 'the folder '$1' was modified at ';
find -type d -name 'kam*' -exec stat -c '%y %n' '' ;
I must go through every folder and output text echo 'the file '$1' was modified at '; and print the date like in the image.
I would like a result like this:
netcom@hotspot:~$ bash script.sh testRegex Pub
the folder testRegex was modified on may 15 01:19
the folder Public was modified on may 19 01:19
the folder Pubos was modified on may 19 01:19
14.04 command-line bash
edited Jun 7 at 23:15
Digital Trauma
1,495517
1,495517
asked Jun 7 at 7:18
Muh
253
253
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
6
down vote
accepted
You can use find itself to print the whole thing:
for pattern
do
find . -type d -name "*$pattern*" -printf 'The folder %P was modified on %tn'
done
for pattern; do ... done loops over all the arguments, with the pattern variable set to each argument in turn.
With find, %P and %t give the path to the file and modification time in -printf.
1
+1 âÂÂ%Tb %Td %TH:%TM(e.g.May 15 01:19) instead of%tgives a format like OP requested.
â dessert
Jun 7 at 8:43
add a comment |Â
up vote
5
down vote
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
add a comment |Â
up vote
4
down vote
The find command can do what you need with one line
You may have a look at the printf action in find
Seeman find for parameters details of printf
Example
find /PATH/TO/SCAN -type d -iname '*pub*' -printf "%p %TY-%Tm-%Td %TH:%TMn"
-type d : search for folders
-iname '*pub*' : find the pattern case insensitive
%p : display path of found folder
%TY : time Year
%Tm : time month
%Td : time day
%TH : time hour
%TM : time minutes
%TS : time seconds
For more information
Official webpage for GNU find
25 Practical examples of the find command
add a comment |Â
up vote
2
down vote
Here's a slight variation, which makes use of -regex instead of -names:
find . -type d -regex ".*($1).*$" -printf 'The folder %P was modified on %Tb %Td %TH:%TMn'
This can be either a single-line script or better yet - a function. Call it as so:
./finder.sh 'Vid|Doc'
This makes for more idiomatic, grep-like approach.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
You can use find itself to print the whole thing:
for pattern
do
find . -type d -name "*$pattern*" -printf 'The folder %P was modified on %tn'
done
for pattern; do ... done loops over all the arguments, with the pattern variable set to each argument in turn.
With find, %P and %t give the path to the file and modification time in -printf.
1
+1 âÂÂ%Tb %Td %TH:%TM(e.g.May 15 01:19) instead of%tgives a format like OP requested.
â dessert
Jun 7 at 8:43
add a comment |Â
up vote
6
down vote
accepted
You can use find itself to print the whole thing:
for pattern
do
find . -type d -name "*$pattern*" -printf 'The folder %P was modified on %tn'
done
for pattern; do ... done loops over all the arguments, with the pattern variable set to each argument in turn.
With find, %P and %t give the path to the file and modification time in -printf.
1
+1 âÂÂ%Tb %Td %TH:%TM(e.g.May 15 01:19) instead of%tgives a format like OP requested.
â dessert
Jun 7 at 8:43
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
You can use find itself to print the whole thing:
for pattern
do
find . -type d -name "*$pattern*" -printf 'The folder %P was modified on %tn'
done
for pattern; do ... done loops over all the arguments, with the pattern variable set to each argument in turn.
With find, %P and %t give the path to the file and modification time in -printf.
You can use find itself to print the whole thing:
for pattern
do
find . -type d -name "*$pattern*" -printf 'The folder %P was modified on %tn'
done
for pattern; do ... done loops over all the arguments, with the pattern variable set to each argument in turn.
With find, %P and %t give the path to the file and modification time in -printf.
answered Jun 7 at 7:42
muru
128k19269459
128k19269459
1
+1 âÂÂ%Tb %Td %TH:%TM(e.g.May 15 01:19) instead of%tgives a format like OP requested.
â dessert
Jun 7 at 8:43
add a comment |Â
1
+1 âÂÂ%Tb %Td %TH:%TM(e.g.May 15 01:19) instead of%tgives a format like OP requested.
â dessert
Jun 7 at 8:43
1
1
+1 âÂÂ
%Tb %Td %TH:%TM (e.g. May 15 01:19) instead of %t gives a format like OP requested.â dessert
Jun 7 at 8:43
+1 âÂÂ
%Tb %Td %TH:%TM (e.g. May 15 01:19) instead of %t gives a format like OP requested.â dessert
Jun 7 at 8:43
add a comment |Â
up vote
5
down vote
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
add a comment |Â
up vote
5
down vote
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
add a comment |Â
up vote
5
down vote
up vote
5
down vote
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
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
edited Jun 7 at 11:09
answered Jun 7 at 8:06
dessert
19.4k55494
19.4k55494
add a comment |Â
add a comment |Â
up vote
4
down vote
The find command can do what you need with one line
You may have a look at the printf action in find
Seeman find for parameters details of printf
Example
find /PATH/TO/SCAN -type d -iname '*pub*' -printf "%p %TY-%Tm-%Td %TH:%TMn"
-type d : search for folders
-iname '*pub*' : find the pattern case insensitive
%p : display path of found folder
%TY : time Year
%Tm : time month
%Td : time day
%TH : time hour
%TM : time minutes
%TS : time seconds
For more information
Official webpage for GNU find
25 Practical examples of the find command
add a comment |Â
up vote
4
down vote
The find command can do what you need with one line
You may have a look at the printf action in find
Seeman find for parameters details of printf
Example
find /PATH/TO/SCAN -type d -iname '*pub*' -printf "%p %TY-%Tm-%Td %TH:%TMn"
-type d : search for folders
-iname '*pub*' : find the pattern case insensitive
%p : display path of found folder
%TY : time Year
%Tm : time month
%Td : time day
%TH : time hour
%TM : time minutes
%TS : time seconds
For more information
Official webpage for GNU find
25 Practical examples of the find command
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The find command can do what you need with one line
You may have a look at the printf action in find
Seeman find for parameters details of printf
Example
find /PATH/TO/SCAN -type d -iname '*pub*' -printf "%p %TY-%Tm-%Td %TH:%TMn"
-type d : search for folders
-iname '*pub*' : find the pattern case insensitive
%p : display path of found folder
%TY : time Year
%Tm : time month
%Td : time day
%TH : time hour
%TM : time minutes
%TS : time seconds
For more information
Official webpage for GNU find
25 Practical examples of the find command
The find command can do what you need with one line
You may have a look at the printf action in find
Seeman find for parameters details of printf
Example
find /PATH/TO/SCAN -type d -iname '*pub*' -printf "%p %TY-%Tm-%Td %TH:%TMn"
-type d : search for folders
-iname '*pub*' : find the pattern case insensitive
%p : display path of found folder
%TY : time Year
%Tm : time month
%Td : time day
%TH : time hour
%TM : time minutes
%TS : time seconds
For more information
Official webpage for GNU find
25 Practical examples of the find command
edited Jun 7 at 7:59
answered Jun 7 at 7:45
cmak.fr
1,529918
1,529918
add a comment |Â
add a comment |Â
up vote
2
down vote
Here's a slight variation, which makes use of -regex instead of -names:
find . -type d -regex ".*($1).*$" -printf 'The folder %P was modified on %Tb %Td %TH:%TMn'
This can be either a single-line script or better yet - a function. Call it as so:
./finder.sh 'Vid|Doc'
This makes for more idiomatic, grep-like approach.
add a comment |Â
up vote
2
down vote
Here's a slight variation, which makes use of -regex instead of -names:
find . -type d -regex ".*($1).*$" -printf 'The folder %P was modified on %Tb %Td %TH:%TMn'
This can be either a single-line script or better yet - a function. Call it as so:
./finder.sh 'Vid|Doc'
This makes for more idiomatic, grep-like approach.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Here's a slight variation, which makes use of -regex instead of -names:
find . -type d -regex ".*($1).*$" -printf 'The folder %P was modified on %Tb %Td %TH:%TMn'
This can be either a single-line script or better yet - a function. Call it as so:
./finder.sh 'Vid|Doc'
This makes for more idiomatic, grep-like approach.
Here's a slight variation, which makes use of -regex instead of -names:
find . -type d -regex ".*($1).*$" -printf 'The folder %P was modified on %Tb %Td %TH:%TMn'
This can be either a single-line script or better yet - a function. Call it as so:
./finder.sh 'Vid|Doc'
This makes for more idiomatic, grep-like approach.
edited Jun 7 at 8:54
dessert
19.4k55494
19.4k55494
answered Jun 7 at 8:42
Sergiy Kolodyazhnyy
63.6k9127272
63.6k9127272
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1044386%2fshell-to-print-modification-date-of-all-directories-name-match-pattern%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password