I need to write a script that look for the largest file in a given directory (including its subdirectories).
I figured out that If I use "tree" to generate a textual representation of all files, maybe then I can have the script to compare the sizes and output the largest one.
I ended up with a text file that looks something like this
.
[ 939] "./Documents/Alfa/driver/wlan0up"
[ 234] "./Documents/Alfa/driver/wpa1.conf"
[ 1623520] "./Documents/Alfa/driver/wpa_supplicant-0.5.5.zip"
[ 5488640] "./Documents/Alfa/R36-V1.2.1.2b6.img"
[ 3385] "./Documents/C code/Ide.s"
[ 4096] "./Documents/fluxion-master"
[ 25] "./Documents/fluxion-master/_config.yml"
[ 4096] "./Documents/fluxion-master/docs"
[ 35141] "./Documents/fluxion-master/docs/LICENSE"
[ 83788] "./Documents/fluxion-master/fluxion"
~~ long list of other files
[ 6909] "./.ZAP/session/untitled2.script"
[ 64411] "./.ZAP/zap.log"
[ 4096] "./.zenmap"
[ 0] "./.zenmap/recent_scans.txt"
[ 2018] "./.zenmap/scan_profile.usp"
[ 85] "./.zenmap/target_list.txt"
[ 1486] "./.zenmap/zenmap.conf"
[ 409600] "./.zenmap/zenmap.db"
[ 5] "./.zenmap/zenmap_version"
429 directories, 3327 files
Now, all I need is to have the script read through the list and compare the sizes until the list ends, then output the largest file's name and size.
I went through some other stackoverflow entries, using sed and grep, but didn't get any luck.
Read a file line by line assigning the value to a variable
Looping through the content of a file in Bash?
Please note that tree is capable of formatting the output as xml file, using tags and attributes like <directory name="fileName" size="XXXX"></directory>
so if parsing the xml file is easier, that would be fine too.
folders are also listed in there, but we can ignore that.
Any help would be appreciated, Thanks