calculate the front of a specific directory Ten a large file
In a given directory, want to know which large files exist, take the top 10, by file size ranking
(1) , using awk to achieve
#!/bin/bash
Path=/root/shell
Find $path-type F | awk ' {
Var=$0
"Ls-l" var |getline var1
Split (Var1,a, "")
FILENAME=A[9]
FILESIZE=A[5]
printf ("%s%s\n", filename,filesize) | "Sort-k2-n-r|head-10"
}
‘
The above notation can cause memory overflow when there are more files.
Improve as follows:
#!/bin/bash
Path=/root/shell
Echo >r2.txt
Find $path-type F | awk ' {
Var=$0
"Ls-l" var |getline var1
Split (Var1,a, "")
FILENAME=A[9]
FILESIZE=A[5]
printf ("%s%s\n", filename,filesize)
}
' >r2.txt
Cat R2.txt|sort-k2-n-r | Head-10
(2) , using while to achieve
#!/bin/bash
Path=/root/shell
Echo >r1.txt
Find $path-type F|while Read line
Do
Filename= ' ls-l $line |awk ' {print $9} '
Filesize= ' ls-l $line |awk ' {print $} '
echo $filename $filesize >>r1.txt
Done
Cat R1.txt|sort-k2-n-r | Head-10
This article is from the "operation and maintenance of micro-letter" blog, please be sure to keep this source http://weixiaoxin.blog.51cto.com/13270051/1964074
Linux Shell Programming---Calculate the first 10 large files in a specific directory