Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all files in a .tar.bz2, sorted by size

I use this command to list all files in an archive:

tar jtvf blah.tar.bz2

How to list them sorted by size? Or list only the biggest files (i.e. files bigger than, say, 10MB)?

like image 823
Basj Avatar asked Dec 18 '22 13:12

Basj


1 Answers

list files, filter by size, print only size+space+path, and sort by size only, descending order:

size=10485760
tar tvf blah.tar.bz2 \
    | awk -v size="$size" '$3 >= size {print $3" "$6}' \
    | sort -t' ' -k1,1nr
like image 137
Peter Avatar answered Jan 13 '23 20:01

Peter