Skip to content

Instantly share code, notes, and snippets.

@serhiijko
Forked from Iman/clean.sh
Created June 16, 2021 04:02
Show Gist options
  • Save serhiijko/e4732bde01d77b5ace881ea64ee67ef1 to your computer and use it in GitHub Desktop.
Save serhiijko/e4732bde01d77b5ace881ea64ee67ef1 to your computer and use it in GitHub Desktop.

Revisions

  1. @Iman Iman revised this gist Feb 25, 2016. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions clean.sh
    Original file line number Diff line number Diff line change
    @@ -13,10 +13,12 @@ do
    done

    #Getting rid of partial packages
    apt-get autoclean
    apt-get clean && apt-get autoclean
    apt-get remove --purge -y software-properties-common

    #Getting rid of no longer required packages
    apt-get autoremove
    apt-get autoremove -y


    #Getting rid of orphaned packages
    deborphan | xargs sudo apt-get -y remove --purge
    @@ -27,6 +29,8 @@ apt-get clean
    # Remove the Trash
    rm -rf /home/*/.local/share/Trash/*/**
    rm -rf /root/.local/share/Trash/*/**

    # Remove Man
    rm -rf /usr/share/man/??
    rm -rf /usr/share/man/??_*

  2. @Iman Iman revised this gist Feb 25, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions clean.sh
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,8 @@ apt-get clean
    # Remove the Trash
    rm -rf /home/*/.local/share/Trash/*/**
    rm -rf /root/.local/share/Trash/*/**
    rm -rf /usr/share/man/??
    rm -rf /usr/share/man/??_*

    #Delete all .gz and rotated file
    find /var/log -type f -regex ".*\.gz$" | xargs rm -Rf
  3. @Iman Iman created this gist Jul 2, 2015.
    42 changes: 42 additions & 0 deletions clean.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/sh

    #Check the Drive Space Used by Cached Files
    du -sh /var/cache/apt/archives

    #Clean all the log file
    #for logs in `find /var/log -type f`; do > $logs; done

    logs=`find /var/log -type f`
    for i in $logs
    do
    > $i
    done

    #Getting rid of partial packages
    apt-get autoclean

    #Getting rid of no longer required packages
    apt-get autoremove

    #Getting rid of orphaned packages
    deborphan | xargs sudo apt-get -y remove --purge

    #Free up space by clean out the cached packages
    apt-get clean

    # Remove the Trash
    rm -rf /home/*/.local/share/Trash/*/**
    rm -rf /root/.local/share/Trash/*/**

    #Delete all .gz and rotated file
    find /var/log -type f -regex ".*\.gz$" | xargs rm -Rf
    find /var/log -type f -regex ".*\.[0-9]$" | xargs rm -Rf

    #Cleaning the old kernels
    dpkg-query -l|grep linux-im*
    #dpkg-query -l |grep linux-im*|awk '{print $2}'
    apt-get purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | head -n -1) --assume-yes
    apt-get install linux-headers-`uname -r|cut -d'-' -f3`-`uname -r|cut -d'-' -f4`

    #Cleaning is completed
    echo "Cleaning is completed"