Listing files by year [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm looking for some help with a command. I have a large-ish directory of files. What I want to do is sort these a little better.
For example, I want to see how many files and directories I have that have a unique year (so I guess I end up with a range of years in output).
I have been trying by list with ls -l
and I added in grep
so ls -l | grep -c
but its the unique date that is catching me.
Anybody help?
linux
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, Kusalananda, don_crissti, Anthon Oct 3 '17 at 18:37
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
0
down vote
favorite
I'm looking for some help with a command. I have a large-ish directory of files. What I want to do is sort these a little better.
For example, I want to see how many files and directories I have that have a unique year (so I guess I end up with a range of years in output).
I have been trying by list with ls -l
and I added in grep
so ls -l | grep -c
but its the unique date that is catching me.
Anybody help?
linux
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, Kusalananda, don_crissti, Anthon Oct 3 '17 at 18:37
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
3
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm looking for some help with a command. I have a large-ish directory of files. What I want to do is sort these a little better.
For example, I want to see how many files and directories I have that have a unique year (so I guess I end up with a range of years in output).
I have been trying by list with ls -l
and I added in grep
so ls -l | grep -c
but its the unique date that is catching me.
Anybody help?
linux
I'm looking for some help with a command. I have a large-ish directory of files. What I want to do is sort these a little better.
For example, I want to see how many files and directories I have that have a unique year (so I guess I end up with a range of years in output).
I have been trying by list with ls -l
and I added in grep
so ls -l | grep -c
but its the unique date that is catching me.
Anybody help?
linux
linux
edited Oct 3 '17 at 15:46
Kusalananda
105k14209326
105k14209326
asked Oct 3 '17 at 15:07
Costacoffee
31
31
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, Kusalananda, don_crissti, Anthon Oct 3 '17 at 18:37
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Jeff Schaller, Stephen Rauch, Kusalananda, don_crissti, Anthon Oct 3 '17 at 18:37
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
3
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45
add a comment |Â
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
3
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
3
3
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Try using:
ls -l --time-style=long-iso | grep -c ' 2017-'
Replace 2017 with whatever 4 digit year you want. The --time-style
option will cause ls to print ISO 8601 timestamps instead of the short, vague human readable stuff it does by default. The expression passed to grep will then match the year at the beginning of the timestamp, and should just pull out the lines for the files that were modified that year (providing you have no filenames that start with those four digits followed by a dash).
Note that this will likely only work with the GNU implementation of ls
(I know for a fact it doesn't work with the busybox, FreeBSD, NetBSD, or MINIX implementations, and I'm pretty sure it doesn't work with the Solaris one either).
As requested in the comments, the following (long and convoluted) command can be used to get the number of individual years represented:
ls -l --time-style=long-iso | tail +2 | sed -n 's/ */ /gp' - | cut -d ' ' -f 6 | cut -d '-' -f 1 | sort -u | wc -l
The tail command strips off the first (useless) line showing totals. The sed command collapses runs of spaces to single spaces. The first cut command pulls out the year-month-day field, the second pulls just the year out of that, which the sort command then reduces to one instance of each year, and the wc command finally spits out the number.
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Try using:
ls -l --time-style=long-iso | grep -c ' 2017-'
Replace 2017 with whatever 4 digit year you want. The --time-style
option will cause ls to print ISO 8601 timestamps instead of the short, vague human readable stuff it does by default. The expression passed to grep will then match the year at the beginning of the timestamp, and should just pull out the lines for the files that were modified that year (providing you have no filenames that start with those four digits followed by a dash).
Note that this will likely only work with the GNU implementation of ls
(I know for a fact it doesn't work with the busybox, FreeBSD, NetBSD, or MINIX implementations, and I'm pretty sure it doesn't work with the Solaris one either).
As requested in the comments, the following (long and convoluted) command can be used to get the number of individual years represented:
ls -l --time-style=long-iso | tail +2 | sed -n 's/ */ /gp' - | cut -d ' ' -f 6 | cut -d '-' -f 1 | sort -u | wc -l
The tail command strips off the first (useless) line showing totals. The sed command collapses runs of spaces to single spaces. The first cut command pulls out the year-month-day field, the second pulls just the year out of that, which the sort command then reduces to one instance of each year, and the wc command finally spits out the number.
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
add a comment |Â
up vote
0
down vote
accepted
Try using:
ls -l --time-style=long-iso | grep -c ' 2017-'
Replace 2017 with whatever 4 digit year you want. The --time-style
option will cause ls to print ISO 8601 timestamps instead of the short, vague human readable stuff it does by default. The expression passed to grep will then match the year at the beginning of the timestamp, and should just pull out the lines for the files that were modified that year (providing you have no filenames that start with those four digits followed by a dash).
Note that this will likely only work with the GNU implementation of ls
(I know for a fact it doesn't work with the busybox, FreeBSD, NetBSD, or MINIX implementations, and I'm pretty sure it doesn't work with the Solaris one either).
As requested in the comments, the following (long and convoluted) command can be used to get the number of individual years represented:
ls -l --time-style=long-iso | tail +2 | sed -n 's/ */ /gp' - | cut -d ' ' -f 6 | cut -d '-' -f 1 | sort -u | wc -l
The tail command strips off the first (useless) line showing totals. The sed command collapses runs of spaces to single spaces. The first cut command pulls out the year-month-day field, the second pulls just the year out of that, which the sort command then reduces to one instance of each year, and the wc command finally spits out the number.
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Try using:
ls -l --time-style=long-iso | grep -c ' 2017-'
Replace 2017 with whatever 4 digit year you want. The --time-style
option will cause ls to print ISO 8601 timestamps instead of the short, vague human readable stuff it does by default. The expression passed to grep will then match the year at the beginning of the timestamp, and should just pull out the lines for the files that were modified that year (providing you have no filenames that start with those four digits followed by a dash).
Note that this will likely only work with the GNU implementation of ls
(I know for a fact it doesn't work with the busybox, FreeBSD, NetBSD, or MINIX implementations, and I'm pretty sure it doesn't work with the Solaris one either).
As requested in the comments, the following (long and convoluted) command can be used to get the number of individual years represented:
ls -l --time-style=long-iso | tail +2 | sed -n 's/ */ /gp' - | cut -d ' ' -f 6 | cut -d '-' -f 1 | sort -u | wc -l
The tail command strips off the first (useless) line showing totals. The sed command collapses runs of spaces to single spaces. The first cut command pulls out the year-month-day field, the second pulls just the year out of that, which the sort command then reduces to one instance of each year, and the wc command finally spits out the number.
Try using:
ls -l --time-style=long-iso | grep -c ' 2017-'
Replace 2017 with whatever 4 digit year you want. The --time-style
option will cause ls to print ISO 8601 timestamps instead of the short, vague human readable stuff it does by default. The expression passed to grep will then match the year at the beginning of the timestamp, and should just pull out the lines for the files that were modified that year (providing you have no filenames that start with those four digits followed by a dash).
Note that this will likely only work with the GNU implementation of ls
(I know for a fact it doesn't work with the busybox, FreeBSD, NetBSD, or MINIX implementations, and I'm pretty sure it doesn't work with the Solaris one either).
As requested in the comments, the following (long and convoluted) command can be used to get the number of individual years represented:
ls -l --time-style=long-iso | tail +2 | sed -n 's/ */ /gp' - | cut -d ' ' -f 6 | cut -d '-' -f 1 | sort -u | wc -l
The tail command strips off the first (useless) line showing totals. The sed command collapses runs of spaces to single spaces. The first cut command pulls out the year-month-day field, the second pulls just the year out of that, which the sort command then reduces to one instance of each year, and the wc command finally spits out the number.
edited Oct 3 '17 at 19:49
answered Oct 3 '17 at 18:29
Austin Hemmelgarn
5,2041915
5,2041915
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
add a comment |Â
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
Thanks for that Austin. If I wanted to count all the years, how you I go about doing that. Unique years, so if I have files from 2014, 2016 & 2017 it prints out '3' as in you have three years with files with these years. Would I be going 0-2017 or use some sort of wildcard? Hope that makes sense.
â Costacoffee
Oct 3 '17 at 19:33
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
@Costacoffee Updated the answer with a command to do that.
â Austin Hemmelgarn
Oct 3 '17 at 19:49
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
Perfect, thanks Austin. That's some command! Thanks for the help.
â Costacoffee
Oct 3 '17 at 20:13
add a comment |Â
Use find and -regex
â Raman Sailopal
Oct 3 '17 at 15:09
3
Any hint about where the year is, please? In a filename? How are the filenames formatted? In a timestamp? Inside the file somewhere?
â Kusalananda
Oct 3 '17 at 15:45