Go through all folders whose names contain a given pattern [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
File list command line (hidden and subfolders)
2 answers
let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .
stat -c %y "$1"
this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name
14.04 command-line bash
marked as duplicate by ñÃÂsýù÷, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
File list command line (hidden and subfolders)
2 answers
let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .
stat -c %y "$1"
this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name
14.04 command-line bash
marked as duplicate by ñÃÂsýù÷, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
ll -lt | grep af
you can try this
â neferpitou
Jun 6 at 13:58
You can run for loop. Something, like, for i inls af*
; do stat -c %y; done
â Josef Klimuk
Jun 6 at 14:16
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
File list command line (hidden and subfolders)
2 answers
let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .
stat -c %y "$1"
this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name
14.04 command-line bash
This question already has an answer here:
File list command line (hidden and subfolders)
2 answers
let suppose I have folders with names af32, af42, af, and I want to print the last modification date of all folders whose have af* pattern for example .
I writed shell that will take folder or files as parameter and return modification date for that folder .
stat -c %y "$1"
this code will return the last modification date to folder .
but how can I apply this code to more than one folder whose have same pattern in their name
This question already has an answer here:
File list command line (hidden and subfolders)
2 answers
14.04 command-line bash
asked Jun 6 at 13:51
Muh
253
253
marked as duplicate by ñÃÂsýù÷, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ñÃÂsýù÷, David Foerster, Eric Carvalho, vidarlo, Amith KK Jun 9 at 19:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
ll -lt | grep af
you can try this
â neferpitou
Jun 6 at 13:58
You can run for loop. Something, like, for i inls af*
; do stat -c %y; done
â Josef Klimuk
Jun 6 at 14:16
add a comment |Â
ll -lt | grep af
you can try this
â neferpitou
Jun 6 at 13:58
You can run for loop. Something, like, for i inls af*
; do stat -c %y; done
â Josef Klimuk
Jun 6 at 14:16
ll -lt | grep af
you can try thisâ neferpitou
Jun 6 at 13:58
ll -lt | grep af
you can try thisâ neferpitou
Jun 6 at 13:58
You can run for loop. Something, like, for i in
ls af*
; do stat -c %y; doneâ Josef Klimuk
Jun 6 at 14:16
You can run for loop. Something, like, for i in
ls af*
; do stat -c %y; doneâ Josef Klimuk
Jun 6 at 14:16
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You can use find
to search recursively in search_folder/
for directories (-type d
) matching a specific pattern glob (e.g. -name 'af*'
):
find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;
This will then execute (-exec ... ;
) the command stat -c '%y %n' ''
on each of the search results, replacing with the result path, starting with the given
search_folder/
.
Note that I modified your stat
output to include the file name/path %n
in the result, because otherwise you wouldn't see what file each modification date belongs to.
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
You have to replacesearch_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run thestat
command on all matching folders below it.
â Byte Commander
Jun 6 at 14:32
1
More efficient with:-exec ⦠+
â dessert
Jun 6 at 16:31
add a comment |Â
up vote
1
down vote
You can use shell globbing as follows:
stat -c %y af*/
af*/
matches every directory in the current directory beginning with âÂÂafâÂÂ.
If this throws an error like
bash: /usr/bin/stat: Argument list too long
use this printf
approach instead:
printf '%s' af*/ | xargs -0 stat -c %y
Example run
You might want to add %n
to stat
âÂÂs outputâ¦
$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use find
to search recursively in search_folder/
for directories (-type d
) matching a specific pattern glob (e.g. -name 'af*'
):
find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;
This will then execute (-exec ... ;
) the command stat -c '%y %n' ''
on each of the search results, replacing with the result path, starting with the given
search_folder/
.
Note that I modified your stat
output to include the file name/path %n
in the result, because otherwise you wouldn't see what file each modification date belongs to.
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
You have to replacesearch_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run thestat
command on all matching folders below it.
â Byte Commander
Jun 6 at 14:32
1
More efficient with:-exec ⦠+
â dessert
Jun 6 at 16:31
add a comment |Â
up vote
1
down vote
accepted
You can use find
to search recursively in search_folder/
for directories (-type d
) matching a specific pattern glob (e.g. -name 'af*'
):
find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;
This will then execute (-exec ... ;
) the command stat -c '%y %n' ''
on each of the search results, replacing with the result path, starting with the given
search_folder/
.
Note that I modified your stat
output to include the file name/path %n
in the result, because otherwise you wouldn't see what file each modification date belongs to.
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
You have to replacesearch_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run thestat
command on all matching folders below it.
â Byte Commander
Jun 6 at 14:32
1
More efficient with:-exec ⦠+
â dessert
Jun 6 at 16:31
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use find
to search recursively in search_folder/
for directories (-type d
) matching a specific pattern glob (e.g. -name 'af*'
):
find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;
This will then execute (-exec ... ;
) the command stat -c '%y %n' ''
on each of the search results, replacing with the result path, starting with the given
search_folder/
.
Note that I modified your stat
output to include the file name/path %n
in the result, because otherwise you wouldn't see what file each modification date belongs to.
You can use find
to search recursively in search_folder/
for directories (-type d
) matching a specific pattern glob (e.g. -name 'af*'
):
find search_folder/ -type d -name 'af*' -exec stat -c '%y %n' '' ;
This will then execute (-exec ... ;
) the command stat -c '%y %n' ''
on each of the search results, replacing with the result path, starting with the given
search_folder/
.
Note that I modified your stat
output to include the file name/path %n
in the result, because otherwise you wouldn't see what file each modification date belongs to.
answered Jun 6 at 13:59
Byte Commander
57.9k26155263
57.9k26155263
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
You have to replacesearch_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run thestat
command on all matching folders below it.
â Byte Commander
Jun 6 at 14:32
1
More efficient with:-exec ⦠+
â dessert
Jun 6 at 16:31
add a comment |Â
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
You have to replacesearch_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run thestat
command on all matching folders below it.
â Byte Commander
Jun 6 at 14:32
1
More efficient with:-exec ⦠+
â dessert
Jun 6 at 16:31
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
yes thank you for your reply . the code working fine but for one folder. if I have folders with name af1,af2,af3 that code will give me result just for one folder
â Muh
Jun 6 at 14:21
1
1
You have to replace
search_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat
command on all matching folders below it.â Byte Commander
Jun 6 at 14:32
You have to replace
search_folder/
with a parent directory that contains all the folders of which you want the info. Then it will recursively search inside that location and run the stat
command on all matching folders below it.â Byte Commander
Jun 6 at 14:32
1
1
More efficient with:
-exec ⦠+
â dessert
Jun 6 at 16:31
More efficient with:
-exec ⦠+
â dessert
Jun 6 at 16:31
add a comment |Â
up vote
1
down vote
You can use shell globbing as follows:
stat -c %y af*/
af*/
matches every directory in the current directory beginning with âÂÂafâÂÂ.
If this throws an error like
bash: /usr/bin/stat: Argument list too long
use this printf
approach instead:
printf '%s' af*/ | xargs -0 stat -c %y
Example run
You might want to add %n
to stat
âÂÂs outputâ¦
$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/
add a comment |Â
up vote
1
down vote
You can use shell globbing as follows:
stat -c %y af*/
af*/
matches every directory in the current directory beginning with âÂÂafâÂÂ.
If this throws an error like
bash: /usr/bin/stat: Argument list too long
use this printf
approach instead:
printf '%s' af*/ | xargs -0 stat -c %y
Example run
You might want to add %n
to stat
âÂÂs outputâ¦
$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can use shell globbing as follows:
stat -c %y af*/
af*/
matches every directory in the current directory beginning with âÂÂafâÂÂ.
If this throws an error like
bash: /usr/bin/stat: Argument list too long
use this printf
approach instead:
printf '%s' af*/ | xargs -0 stat -c %y
Example run
You might want to add %n
to stat
âÂÂs outputâ¦
$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/
You can use shell globbing as follows:
stat -c %y af*/
af*/
matches every directory in the current directory beginning with âÂÂafâÂÂ.
If this throws an error like
bash: /usr/bin/stat: Argument list too long
use this printf
approach instead:
printf '%s' af*/ | xargs -0 stat -c %y
Example run
You might want to add %n
to stat
âÂÂs outputâ¦
$ ls
af af32 af42 bf cg45
$ stat -c %y af*/
2018-06-05 18:59:55.355277977 +0200
2018-06-04 19:01:28.968869600 +0200
2018-06-06 18:58:15.968639269 +0200
$ stat -c '%y %n' af*/
2018-06-05 18:59:55.355277977 +0200 af/
2018-06-04 19:01:28.968869600 +0200 af32/
2018-06-06 18:58:15.968639269 +0200 af42/
edited Jun 6 at 17:59
answered Jun 6 at 17:06
dessert
19.4k55494
19.4k55494
add a comment |Â
add a comment |Â
ll -lt | grep af
you can try thisâ neferpitou
Jun 6 at 13:58
You can run for loop. Something, like, for i in
ls af*
; do stat -c %y; doneâ Josef Klimuk
Jun 6 at 14:16