Extract top 10 biggest files from tar archive Linux

前端 未结 1 519
逝去的感伤
逝去的感伤 2021-01-28 12:01

I want to extract only the top 10 biggest files from a tar archive using Linux terminal. I can insert the path of the files to be extracted, but I want to know if I can do it us

相关标签:
1条回答
  • 2021-01-28 12:29

    You can use below commands to actually extract only the top 10 biggest files from a tar.

    files=$(tar -tvf <tar-name> |sort -n -r |egrep -v "^d"|head | awk '{print $9}')
    tar -xvf <tar-name> $files
    

    Let me explain what it's doing exactly :

    This command will list archive contents to stdout.

    tar -tvf <tar-name>
    

    This will sort the content.

    tar -tvf <tar-name> |sort -n -r
    

    This will exlcude the directories if any :

    tar -tvf <tar-name> |sort -n -r |egrep -v "^d"
    

    This will print the top 10 files (head by default prints 10):

    tar -tvf <tar-name> |sort -n -r |egrep -v "^d"|head
    

    This will fetch only the filenames :

    tar -tvf <tar-name> |sort -n -r |egrep -v "^d"|head | awk '{print $9}'
    

    Once we get the filenames, we save it in files variable and then we can use below command to fetch the exact files from the tarball :

    tar -xvf <tar-name> $files
    
    0 讨论(0)
提交回复
热议问题