The power of bash

In this absolutely tiny material, we will write a script that removes files and directories that we do not need from the computer. This will be useful for those who are currently performing these manipulations manually.





#!/bin/bash
# ,        , :
search_arr=(WetTrains LedForm WyChart)

#                                                                                   
echo Find and delete files and folders contains $search_arr

#    
for item in ${search_arr[*]}
do
    echo Find and remove *$item*
    #     ,    ,
    #     ,    
    sudo find / -iname -name "*$item*" -exec rm -rv {} \;
done

#  ,     ,      
#     wget  
wget "https://download.wettrains.com/wychart-confessional-xxxx.x.x.tar.gz"
wget "https://download.wettrains.com/LedForm-xxxx.x.x.tar.gz"

#       
sudo mv LedForm-xxxx.x.x.tar.gz /opt/
sudo mv wychart-cofessional-xxxx.x.x.tar.gz /opt/

#  
cd /opt/ && sudo tar -xzvf LedForm-xxxx.x.x.tar.gz
cd /opt/ && sudo tar -xzvf wychart-confessional-xxxx.x.x.tar.gz


      
      



Improvement

Often you need to delete something, for example, to free up extra space. Some files become unnecessary and just get in the way. To start using this thing, you just need to make it executable and run:





chmod +x brainduck.sh

./brainduck.sh








You can also schedule it so that it runs, for example, once at 00:00 every first day of a new month:





0 0 1 * * ~/scripts/brainduck.sh







Attempts to add arguments to the call to manage keywords, but in this case it will be possible to remove something unnecessary, which becomes unsafe and requires the implementation of validation mechanisms.





Application

By changing the values ​​inside the search_arr array, you can find different areas for applying this mechanism. You can clear the cache, delete temporary files, program logs, programs themselves. Use this script only if you understand exactly what you are doing and what you want to achieve, because when using certain keywords, it can delete system files.








All Articles