I need some help with Unix commands. I have a diretory that I need to gather the following information on files within it.
1. I need a list of all files from January 1, 2002 to today in descending order of the size of the files (biggest file on top).
2. I need total space used by files created in the directory, between January 1, 2002 and today.
3. i need the number of files created between January 1, 2002 and today.
Thanks for the help.
01-04-2002, 11:35 AM
Knarayan
The command below will give you a list of files created/mod. in Jan(current month) in desc order
ls -lrt|grep `date +%b`
the foll command will give you a sum of bytes for the above files:
ls -lrt|grep `date +%b`|wc -c
The command below will give you the count of the files
ls -lrt|grep `date +%b`|wc -l
You can put this in a shell script and get a row output for the above 3 lists
Hope this helps.
01-04-2002, 11:49 AM
pcotten
ls -lrt|grep `date +%b`
gave me the list of files starting on January 1st till today. I need these files in descending order of the size of the files. That mean I need them listed with the file biggest in size on the top regardless of when it was created.
ls -lrt|grep `date +%b`|wc -c
Does this command give kilobytes or bytes. if it is bytes, the command is missing something.
If I want to change the dates to December 3, 2001 to December 7, 2001, how to modify these commands. Thanks.
01-04-2002, 12:10 PM
svk
List of files from Jan 1, 2002 in desc order of size :
touch -t 200201010000 ref_file
ls -ls `find . -newer ref_file -print`| sort -nr
Total space used by the files for above criteria :
du `find . -newer ref_file -print`|awk 'BEGIN{ total=0 }{total=total+$1}END{ print total}'
This will give you number of OS blocks (which is normally 512 bytes in Unix)
The following command is NOT giving me list of files (in descending order of size) between January 1st and today. it is including files in November, December, etc. It is listing files in descending order but not the correct dates.
List of files from Jan 1, 2002 in desc order of size :
touch -t 200201010000 ref_file
ls -ls `find . -newer ref_file -print`| sort -nr
If I want to change dates (December 3, 2001 to December 7, 2001) how do I accomplish that? Thanks.
01-04-2002, 01:02 PM
svk
Check the syntax for 'touch' and 'find' commands for you Unix flavour.
And the sole reason I posted here was the earlier solution of using date '+%b' was not going to work in Feb or if you needed files older than Jan, 2002.
For that, use the timestamp for the 'ref_file' equal to the start point you need.