If you are looking to delete all the files in Linux Web Server by specifing File Name and File Size,
then follow steps below:
1. Login into your server Terminal via root login.
2. Create a new bash file called
3. Then Copy and the below code and Paste into that file and Save it.
4. Then go to your specified directory where you want to Search and Delete the files by specifying the File Name and File Size as below;
5. Then run the below command
then follow steps below:
1. Login into your server Terminal via root login.
2. Create a new bash file called
clean_up.sh
in one of the locatione.g. /home/my_script/
3. Then Copy and the below code and Paste into that file and Save it.
clear echo ' -------------------------------------------------------------------------' echo ' Cleaning all large size error_log files from all directories.' echo ' -------------------------------------------------------------------------' filename="error_log" filesize="50000" echo " Deleting all files (including subfolders) having Filename:'$filename', Size: greater than $filesize Kb only." echo ' ' echo ' Listing all the files which are greater than 50MB' find / -type f -size +50M -exec du -h {} \; | sort -n echo ' Deleting all the "error_log" files which are greater than 50MB' #find -name "error_log" -size +30000k #-delete find -name "$filename" -size +"$filesize"k -delete echo ' Listing again all the files which are greater than 50MB' find / -type f -size +50M -exec du -h {} \; | sort -n
4. Then go to your specified directory where you want to Search and Delete the files by specifying the File Name and File Size as below;
5. Then run the below command
sh /home/my_script/clean_up.sh