AWK- script which lists number and weight of all files created in certain month [closed]

Clash Royale CLAN TAG#URR8PPP
I need to write a script in AWK which will count all the files and their weight in "/home" directory from all the months and display the list in terminal.
The output should look like this:

linux awk command-line files directory
closed as unclear what you're asking by Thomas Dickey, Jeff Schaller, RalfFriedl, Mr Shunz, Archemar Jan 29 at 9:26
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 |
I need to write a script in AWK which will count all the files and their weight in "/home" directory from all the months and display the list in terminal.
The output should look like this:

linux awk command-line files directory
closed as unclear what you're asking by Thomas Dickey, Jeff Schaller, RalfFriedl, Mr Shunz, Archemar Jan 29 at 9:26
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.
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29
add a comment |
I need to write a script in AWK which will count all the files and their weight in "/home" directory from all the months and display the list in terminal.
The output should look like this:

linux awk command-line files directory
I need to write a script in AWK which will count all the files and their weight in "/home" directory from all the months and display the list in terminal.
The output should look like this:

linux awk command-line files directory
linux awk command-line files directory
edited Jan 27 at 12:02
Rui F Ribeiro
40.1k1479135
40.1k1479135
asked Jan 27 at 11:18
FroozieFroozie
32
32
closed as unclear what you're asking by Thomas Dickey, Jeff Schaller, RalfFriedl, Mr Shunz, Archemar Jan 29 at 9:26
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 Thomas Dickey, Jeff Schaller, RalfFriedl, Mr Shunz, Archemar Jan 29 at 9:26
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.
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29
add a comment |
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29
add a comment |
1 Answer
1
active
oldest
votes
I wrote script in awk which uses system commands ls to list files and stat to get info about file. After that script will print number of files and size in bytes.
#!/usr/bin/awk -f
BEGIN
dir = "/home/matej" #chnage default directory
if(ARGC == 2) #check for command line arguments
dir = ARGV[1]
printf("Listing directory: %sn", dir)
cmd = "ls " dir
m_names[1] = "January"
m_names[2] = "February"
m_names[3] = "March"
m_names[4] = "April"
m_names[5] = "May"
m_names[6] = "June"
m_names[7] = "July"
m_names[8] = "August"
m_names[9] = "September"
m_names[10] = "October"
m_names[11] = "November"
m_names[12] = "December"
while((cmd
Modify two things in this script:
dir = "/home/matej/"change your default directory"stat --printf="%Y %s" "" dir filename """ | getline infouse %W instead of %Y if your system supports time of birth
To run script:
chmod +x script.awk./script.awkor with argument./script.awk /home/user
Output in my system looks like:
Listing directory: /home/matej
month number of files total size of files
January : 7 163860
February : 1 4096
March : 1 4096
April : 1 764
May : 1 4096
June : 3 12288
July : 2 13142852623
August : 2 8192
September: 1 16
October : 8 10975459334
November : 4 44067
December : 10 49152
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I wrote script in awk which uses system commands ls to list files and stat to get info about file. After that script will print number of files and size in bytes.
#!/usr/bin/awk -f
BEGIN
dir = "/home/matej" #chnage default directory
if(ARGC == 2) #check for command line arguments
dir = ARGV[1]
printf("Listing directory: %sn", dir)
cmd = "ls " dir
m_names[1] = "January"
m_names[2] = "February"
m_names[3] = "March"
m_names[4] = "April"
m_names[5] = "May"
m_names[6] = "June"
m_names[7] = "July"
m_names[8] = "August"
m_names[9] = "September"
m_names[10] = "October"
m_names[11] = "November"
m_names[12] = "December"
while((cmd
Modify two things in this script:
dir = "/home/matej/"change your default directory"stat --printf="%Y %s" "" dir filename """ | getline infouse %W instead of %Y if your system supports time of birth
To run script:
chmod +x script.awk./script.awkor with argument./script.awk /home/user
Output in my system looks like:
Listing directory: /home/matej
month number of files total size of files
January : 7 163860
February : 1 4096
March : 1 4096
April : 1 764
May : 1 4096
June : 3 12288
July : 2 13142852623
August : 2 8192
September: 1 16
October : 8 10975459334
November : 4 44067
December : 10 49152
add a comment |
I wrote script in awk which uses system commands ls to list files and stat to get info about file. After that script will print number of files and size in bytes.
#!/usr/bin/awk -f
BEGIN
dir = "/home/matej" #chnage default directory
if(ARGC == 2) #check for command line arguments
dir = ARGV[1]
printf("Listing directory: %sn", dir)
cmd = "ls " dir
m_names[1] = "January"
m_names[2] = "February"
m_names[3] = "March"
m_names[4] = "April"
m_names[5] = "May"
m_names[6] = "June"
m_names[7] = "July"
m_names[8] = "August"
m_names[9] = "September"
m_names[10] = "October"
m_names[11] = "November"
m_names[12] = "December"
while((cmd
Modify two things in this script:
dir = "/home/matej/"change your default directory"stat --printf="%Y %s" "" dir filename """ | getline infouse %W instead of %Y if your system supports time of birth
To run script:
chmod +x script.awk./script.awkor with argument./script.awk /home/user
Output in my system looks like:
Listing directory: /home/matej
month number of files total size of files
January : 7 163860
February : 1 4096
March : 1 4096
April : 1 764
May : 1 4096
June : 3 12288
July : 2 13142852623
August : 2 8192
September: 1 16
October : 8 10975459334
November : 4 44067
December : 10 49152
add a comment |
I wrote script in awk which uses system commands ls to list files and stat to get info about file. After that script will print number of files and size in bytes.
#!/usr/bin/awk -f
BEGIN
dir = "/home/matej" #chnage default directory
if(ARGC == 2) #check for command line arguments
dir = ARGV[1]
printf("Listing directory: %sn", dir)
cmd = "ls " dir
m_names[1] = "January"
m_names[2] = "February"
m_names[3] = "March"
m_names[4] = "April"
m_names[5] = "May"
m_names[6] = "June"
m_names[7] = "July"
m_names[8] = "August"
m_names[9] = "September"
m_names[10] = "October"
m_names[11] = "November"
m_names[12] = "December"
while((cmd
Modify two things in this script:
dir = "/home/matej/"change your default directory"stat --printf="%Y %s" "" dir filename """ | getline infouse %W instead of %Y if your system supports time of birth
To run script:
chmod +x script.awk./script.awkor with argument./script.awk /home/user
Output in my system looks like:
Listing directory: /home/matej
month number of files total size of files
January : 7 163860
February : 1 4096
March : 1 4096
April : 1 764
May : 1 4096
June : 3 12288
July : 2 13142852623
August : 2 8192
September: 1 16
October : 8 10975459334
November : 4 44067
December : 10 49152
I wrote script in awk which uses system commands ls to list files and stat to get info about file. After that script will print number of files and size in bytes.
#!/usr/bin/awk -f
BEGIN
dir = "/home/matej" #chnage default directory
if(ARGC == 2) #check for command line arguments
dir = ARGV[1]
printf("Listing directory: %sn", dir)
cmd = "ls " dir
m_names[1] = "January"
m_names[2] = "February"
m_names[3] = "March"
m_names[4] = "April"
m_names[5] = "May"
m_names[6] = "June"
m_names[7] = "July"
m_names[8] = "August"
m_names[9] = "September"
m_names[10] = "October"
m_names[11] = "November"
m_names[12] = "December"
while((cmd
Modify two things in this script:
dir = "/home/matej/"change your default directory"stat --printf="%Y %s" "" dir filename """ | getline infouse %W instead of %Y if your system supports time of birth
To run script:
chmod +x script.awk./script.awkor with argument./script.awk /home/user
Output in my system looks like:
Listing directory: /home/matej
month number of files total size of files
January : 7 163860
February : 1 4096
March : 1 4096
April : 1 764
May : 1 4096
June : 3 12288
July : 2 13142852623
August : 2 8192
September: 1 16
October : 8 10975459334
November : 4 44067
December : 10 49152
edited Jan 27 at 15:08
answered Jan 27 at 14:27
MatejMatej
966
966
add a comment |
add a comment |
Are you an a system with a filesystem which keeps track of the birth time of a file? Some common filesystems does not do that.
– Kusalananda
Jan 27 at 13:29